[R] Appending many different and separate Excel files using R

R. Michael Weylandt <michael.weylandt@gmail.com> michael.weylandt at gmail.com
Sat Aug 18 00:10:39 CEST 2012



On Aug 17, 2012, at 4:19 PM, Amir Kasaeian <amir_kasaeian at yahoo.com> wrote:

> Dear all, 
> Good day! 
> I have a problem in reading Excel files in R and appending them to each other. Suppose we have several Excel files in a directory with headers and want to use R to append them in a single file with an additional variable in the final file indicating from which files the data come from. 
> As I have many Excel files and their sizes are very big I should write a loop in R to do the work. 
> I will be very happy if you guide and help me to write the codes. 
> Thank you very much in advance. 
> 

Given the overhead of most R/Excel interfaces, I think you might want to look into doing this within Excel only using some basic VBA. 

That said,

do.call(rbind, lapply(dir(pattern = "xls"), function(n) read.xls(n)))

should get you started. You can find read.xls in either the gdata or or xlsReadWrite packages. For more advanced control, look at the XLConnect package, which is, unfortunately, not currently available on OS X.

Cheers,
Michael


> Kind regards, 
> Amir Kasaeian
> 
> 
> 
> 
> Amir Kasaeian, 
> PhD Student in Biostatistics,
> Dept. of Epidemiology and Biostatistics,
> School of Public Health,
> Tehran University of Medical Sciences (TUMS).
> P.B. : 14155-6446
> Cell Phone: +98-912-2063511
> E-mail: akasaeian at razi.tums.ac.ir
> ����������� amir_kasaeian at yahoo.com�� 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list