遍历所有文件
list.files(root_dir)
字符串和变量名的转化
# 取字符串名称的变量get(varible_name)# 取变量的名称为字符串as.character(substitute(variable_name))# 用字符串新定义变量assign(character_name, varible_content)
多个变量拼接的输出方式
sprintf("指标激活率:%f", length(idx_act) / length(coef_all))
mutate中字符串相关操作
# mutate 中切分字符串# 更多方法见:https://stackoverflow.com/questions/42565539/using-strsplit-and-subset-in-dplyr-and-mutateus_tmp %>%mutate(sub_label = sapply(str_split(variable_name, "\\."), function(x) x[1]))
批量加载包的简单写法
library(pacman)pacman::p_load(R451talk, dplyr, stringr, reshape2, corrplot, ggplot2,plotly, knitr, data.table, Hmisc, kableExtra, Matrix,caret, glmnet, xlsx)
&和&&区别
# https://stackoverflow.com/questions/23316161/the-condition-has-length-1-and-only-the-first-element-will-be-usedc(TRUE, TRUE) & c(TRUE, FALSE)# [1] TRUE FALSE# c(TRUE, TRUE) && c(TRUE, FALSE)[1] TRUE
找 Rscripts 路径
R.home()
