简体   繁体   English

如何在 r 中保存具有不同标题的 RDS 文件?

[英]how to save RDS file with different title in r?

I have want to save the cars data in a loop with different title name.我想将汽车数据保存在具有不同标题名称的循环中。

for (i in 1:10)
{ outfilename=paste0(i ,".RDS")
saveRDS(cars, file = "/home/outfilename.RDS")}

however, it looks like the out filename still did not work但是,看起来输出的文件名仍然不起作用

You probably meant something like this:你的意思可能是这样的:

for (i in 1:10){
  outfilename <- paste0("/home/", i ,".RDS")
  saveRDS(cars, file = outfilename)
}

Using lapply使用lapply

lapply(1:10, function(i) 
  saveRDS(cars, file = file.path('/home', paste0(i, ".RDS"))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM