Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert csv to xls using R?

Tags:

r

csv

xls

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.)

like image 731
jenswirf Avatar asked Dec 04 '25 18:12

jenswirf


1 Answers

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=""))
}
like image 172
kahlo Avatar answered Dec 06 '25 07:12

kahlo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!