Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在.txt文件上多次运行脚本,并将每个输出保存在r中的单个表中_R_Loops_Repeat - Fatal编程技术网

在.txt文件上多次运行脚本,并将每个输出保存在r中的单个表中

在.txt文件上多次运行脚本,并将每个输出保存在r中的单个表中,r,loops,repeat,R,Loops,Repeat,我必须对100多个.txt文件进行相关性分析。我有一个脚本,它读取单个文件,以我需要的适当方式组织数据,然后将相关值存储为新变量。由于数据被多次重新格式化,脚本相当大 我的问题。如何使该脚本在所有100+.txt文件上重复运行,并在单个DF中存储所有100+的单个相关值?理想情况下,最终的DF将由两列组成,一列带有.txt ID,另一列带有相关系数,它将有100多行 我可以将脚本复制并粘贴到for循环中吗?如果是这样的话,那会是什么样子?我是新手! 有什么想法吗? 谢谢 如前所述,您可以使用la

我必须对100多个.txt文件进行相关性分析。我有一个脚本,它读取单个文件,以我需要的适当方式组织数据,然后将相关值存储为新变量。由于数据被多次重新格式化,脚本相当大

我的问题。如何使该脚本在所有100+.txt文件上重复运行,并在单个DF中存储所有100+的单个相关值?理想情况下,最终的DF将由两列组成,一列带有.txt ID,另一列带有相关系数,它将有100多行

我可以将脚本复制并粘贴到for循环中吗?如果是这样的话,那会是什么样子?我是新手! 有什么想法吗? 谢谢

如前所述,您可以使用
lappy
执行此操作。在没有看到您的数据的情况下,我建议您这样做:

my.files <- list.files(pattern = "txt")  # use a pattern that only matches the files you want to read in
output <- lapply(my.files, correlation_function)

# Combine list of outputs into a single data.frame
output.df <- do.call(rbind, output)
my.files如前所述,您可以使用
lappy
执行此操作。在没有看到您的数据的情况下,我建议您这样做:

my.files <- list.files(pattern = "txt")  # use a pattern that only matches the files you want to read in
output <- lapply(my.files, correlation_function)

# Combine list of outputs into a single data.frame
output.df <- do.call(rbind, output)

my.files使用
lappy
在多个文件上运行。使用
lappy
在多个文件上运行。谢谢!我要试试看!谢谢我要试试看!