[英]How to load several RData with a loop?
I want to load several RData
files into R. The code I use is我想将几个
RData
文件加载到 R 中。我使用的代码是
for(i in 1:100){
name_i <- paste('path/file_',i,'.RData', sep="")
load(name_i)
}
and I have also tried:我也试过:
for(i in 1:100){
paste('name_',i,sep='') <- paste('path/file_',i,'.RData', sep="")
load(name_i)
}
which resulted in this error:导致此错误:
object 'name.in' not found
What I want is to have each RData
to be loaded as:我想要的是将每个
RData
加载为:
name_1
name_2
.
.
.
name_100
but this is obviously not working.但这显然行不通。 Can anyone give me a solution.
谁能给我一个解决方案。
bests and thanks in advance最好的,提前致谢
Your paste
line is wrong.你的
paste
行是错误的。 This这个
paste('name_',i,sep='') <- paste('path/file_',i,'.RData', sep="")
should be something like ('m note sure of your exact file name).应该类似于(请注意您的确切文件名)。
fname = paste('path/file_',i,'.RData', sep="")
load(fname)
It's also worth thing about using list.files
, so使用
list.files
也是值得的,所以
list.files("path/", pattern="*.RData", full.names="TRUE")
Then looping through the file names.然后循环遍历文件名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.