[R] Import more than one sheet in a single excel file

Keo Ormsby keo.ormsby2 at gmail.com
Tue Aug 11 19:18:48 CEST 2009

rajclinasia escribió:
> Hi Every one,
> my question is, How to Import more than one sheet in a single excel file
> (e.g. 10 sheets in one excel file) into R and create datasets for all the
> sheets in a single excel file without specifying the sheetnames.
> Thank you in Advance.
One way is to use the read.xls() function from package gdata. You will 
need to have Perl installed (one easy choice is 
http://www.activestate.com/activeperl), and you can only read Excel < 
2003 files (not 2007). After running  this code, you can merge the 
resulting list of datafremes with the merge() function. Be sure to have 
a column in each Sheet in the .xls file that corresponds to 
subject/observation, with the same name [see ?merge ]. Then you can use 
the write(),  write.table() or write.csv() functions for exporting the 
resulting data frame to an Excel readable 1 sheet only file.

xls <- file.choose()  #Choose the .xls file to convert
prl <- file.choose()  #Choose the perl.exe file location 
sheet <- list()
for(i in 1:10){
sheet[[i]] <- read.xls(f, sheet=i, perl=prl)

If you plan to use Excel and R a lot, I sincerely recommend using Rexel, 
from http://rcom.univie.ac.at/download.html, it is a great package.

Mexico City.

More information about the R-help mailing list