简体   繁体   English

使用R将大量Excel文件保存为rda

[英]Save a lot of file excel as rda using R

I have 1000 file excel with the name "1.xlsx" "2.xlsx" ... "1000.xlsx". 我有1000个文件excel,名称为“ 1.xlsx”“ 2.xlsx” ...“ 1000.xlsx”。 Then how can i write a loop to save them as "1.rda" "2.rda" ... "1000.rda" without using this code 1000 times 那么我怎么能写一个循环将它们另存为“ 1.rda”“ 2.rda” ...“ 1000.rda”而不使用此代码1000次

j1 <- read.xlsx("1.xlsx",1) j1 <-read.xlsx(“ 1.xlsx”,1)

save(j1, file = "j1.rda") 保存(j1,文件=“ j1.rda”)

Thanks a lot 非常感谢

Does this work? 这样行吗?

library(tidyverse)
xlsx_to_rda <- function(inputname, outputname){
  save(read.xlsx(inputname,1), file = outputname)
}
walk2(paste0(1:1000, ".xlsx"),
      paste0(1:1000, ".rda"),
      xlsx_to_rda)

By the way rds would be a better file format, because it stores just one r object. 顺便说一句,rds将是更好的文件格式,因为它仅存储一个r对象。

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

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