我见过类似的帖子,但没有人专门针对这个问题。我有22个数据帧叫做chr1,chr2,chr3,...,chr22。我想申请一个自制的功能" diff_set"到所有这些数据帧并生成22个名为chr1.1,chr2.1,chr3.1,...,chr22.1的新数据帧。该函数应用于其中一列。例如,对于chr1,我应用diff_set并生成chr1.1:
chr1.1 = diff_set(chr1$POSITION, 200000)
欢迎任何建议!
答案 0 :(得分:2)
只需lapply
您的函数数据框列表 diff_set ,重命名输出列表然后如果真的需要但应该避免运行list2env
以保存单个dfs为单独的对象:
output_list <- lapply(mget(paste0("chr", seq(1,22))),
function(df) diff_set(df$POSITION, 20000))
output_list <- setNames(output_list, paste0("chr", seq(1,22)+0.1))
# FIRST THREE DFS
output_list$chr1.1
output_list$chr2.1
output_list$chr3.1
# OUTPUT EACH DF AS SEPARATE OBJECT
# (BUT CONSIDER AVOIDING THIS AS YOU FLOOD GLOBAL ENVIRONMENT)
list2env(output_list, envir=.GlobalEnv)