[R] read.xls: number of sheets

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jul 2 17:05:14 CEST 2009


If you are on Windows and have Excel on the same machine
then the code here:

http://tolstoy.newcastle.edu.au/R/e6/help/09/03/7736.html

will return the number of worksheets as well as a vector of
the worksheet names.

It seems that the email has somehow caused some of the
lines to wrap so you will have to correct that.

There is also some info on various methods of reading excel
spreadsheets here:
http://wiki.r-project.org/rwiki/doku.php?id=tips:data-io:ms_windows

On Thu, Jul 2, 2009 at 10:22 AM, Lauri Nikkinen<lauri.nikkinen at iki.fi> wrote:
> Hi,
>
> I'm trying to read several Excel sheets from an Excel file into a
> list. I'm using
> read.xls from package 'gdata'. I would like to know how I can
> check the number of sheets before the loop (in the example below) so
> that I could adjust the loop counter? Any suggestions?
>
> DF.list <- list()
> for (i in 1:4) {
>    DF.list[[i]] <- read.xls("sample_file.xls", sheet=i,
> stringsAsFactors = FALSE)
>    }
>
> Thanks,
> -L
>
> ______________________________________________
> 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