这是非常基本的(我怀疑这已经在其他地方被问过了,虽然不是在这里)。
我有大量的 .rda 文件,每个文件都有一个数据框。我想对每个数据框进行计算,因此需要加载它们(load()
)。如果他们是 .RDS 对象,我会喜欢:
#My data
x <- data.frame(a=1:3)
y <- data.frame(a=3:6)
#Save as RDS
saveRDS(x, file = "x.rds")
saveRDS(y, file = "y.rds")
files <- c("x.rds", "y.rds")
data <- lapply(files, readRDS)
#Do something with the data in the list "data"
我怎么能做类似的事情,load
因为你不能将数据 - 只有名称 - 分配给变量:
x <- data.frame(a=1:3)
> x
a
1 1
2 2
3 3
save(x, file= "x.rda")
x <- load("x.rda")
> x
[1] "x"