1

I have data that comes in Excel spreadsheets, with a varying number of sheets. Rather than reading all the sheets, as has been explained elsewhere, I would like to exclude the first sheet when importing into R using the readxl package. Using the example data in the package:

library("readxl")
path <- readxl_example("datasets.xls")
lapply(excel_sheets(path), read_excel, path = path)

If I wanted to read all but the first sheet in this data set, is there a way to do it?

M--
  • 25,431
  • 8
  • 61
  • 93
Lina Bird
  • 451
  • 1
  • 6
  • 11
  • 1
    You're probably going to need to loop through the paths and read in the next sheet until you find one with dim = 0,0, then iterate to the next file. – svenhalvorson Jun 12 '17 at 21:40
  • 1
    Does this do what you want : `lapply(excel_sheets(path)[-1], read_excel, path = path)` ? – Remko Duursma Jun 12 '17 at 23:23
  • Remko - that does exactly what I asked for! If you post it as an answer, I will check it. Svenhalvorson, that might be a good solution for me, as I also need to rename both the sheet and the column. I figured out how to do that individually, but I'm not sure whether that can be done in lapply, or whether a loop would be better. Thank you both! – Lina Bird Jun 13 '17 at 11:55

0 Answers0