问题
I have a folder with few hundred CSV files. What would be the easiest way to convert these to XLS format using R?
(Yes, I know CSV is Excel-compatible but I still have good reason to convert them.)
回答1:
Use the package xlsReadWrite to export to xls:
library(xlsReadWrite)
filenames <- list.files("[path_name]", pattern="*.csv", full.names=TRUE)
for(i in 1:length(filenames)){
a <- read.csv(filenames[i])
write.xls(a, paste("file",i,".xls", sep=""))
}
来源:https://stackoverflow.com/questions/15068915/how-to-convert-csv-to-xls-using-r