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. -- View this message in context: http://www.nabble.com/Import-more-than-one-sheet-in-a-single-excel-file-tp24917331p24917331.html Sent from the R help mailing list archive at Nabble.com.
Gabor Grothendieck
2009-Aug-11 13:46 UTC
[R] Import more than one sheet in a single excel file
In read.xls in the gdata package there is an argument that is 1 for the first sheet, 2 for the second, etc. If you run it with verbose = TRUE it will tell you how many sheets are there. On Tue, Aug 11, 2009 at 9:09 AM, rajclinasia<raj at clinasia.com> wrote:> > 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. > > > -- > View this message in context: http://www.nabble.com/Import-more-than-one-sheet-in-a-single-excel-file-tp24917331p24917331.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >
rajclinasia wrote:> > 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. >Please do read the replies to your same questions some time ago: http://markmail.org/thread/l3dx3fvvtw565pka Dieter -- View this message in context: http://www.nabble.com/Import-more-than-one-sheet-in-a-single-excel-file-tp24917331p24918020.html Sent from the R help mailing list archive at Nabble.com.
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.Hello, 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 example:"C:/Perl/bin/perl.exe" 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. Keo. Mexico City.