Dear R Users, I have to read data from many excel spreadsheets, all which have some frustrating formatting (lots of titles, headers, etc.). I am trying to work directly from source data and the number of the spreadsheets I would have to go through make reformatting one by one a pain. I have found lots of ways to read excel files, but my question is whether there is a way to only read "parts" of excel files. Ex. Specify cells (A1:G20), specify rows and columns to start reading at? Or will I have to hack things together after the fact? The URL below will let you download an example .xls of the kind of thing I am working with: http://www.filedropper.com/exampletable_1 I only want/need the "Code" column names, and the "Code" row names, and the values. What would be the best way of automating the reading of these spreadsheets? Many thanks, Peter
R. Michael Weylandt
2011-Sep-15 04:04 UTC
[R] Reading Parts of Excel Files (within a sheet)
I haven't used it, but I believe the XLConnect package allows for control on a cell-by-cell basis. Check out the extensive example given here: http://www.r-bloggers.com/xlconnect-%E2%80%93-a-platform-independent-interface-to-excel/ Hope this helps, Michael Weylandt On Wed, Sep 14, 2011 at 8:43 PM, Peter Lomas <peter.lomas@ucalgary.ca>wrote:> Dear R Users, > > I have to read data from many excel spreadsheets, all which have some > frustrating formatting (lots of titles, headers, etc.). I am trying > to work directly from source data and the number of the spreadsheets I > would have to go through make reformatting one by one a pain. I have > found lots of ways to read excel files, but my question is whether > there is a way to only read "parts" of excel files. Ex. Specify > cells (A1:G20), specify rows and columns to start reading at? Or will > I have to hack things together after the fact? > > The URL below will let you download an example .xls of the kind of > thing I am working with: > http://www.filedropper.com/exampletable_1 > I only want/need the "Code" column names, and the "Code" row names, > and the values. What would be the best way of automating the reading > of these spreadsheets? > > Many thanks, > Peter > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
Hi Peter, the readWorksheet function of the XLConnect package seems to do what you are looking for. It has arguments startRow, startCol, endRow & endCol. Alternatively, you could define a named region in Excel that encompasses the data that you are interested in. Then you can use the readNamedRegion method to read only the defined range. Best regards, Martin Studer -- View this message in context: http://r.789695.n4.nabble.com/Reading-Parts-of-Excel-Files-within-a-sheet-tp3814447p3856138.html Sent from the R help mailing list archive at Nabble.com.