I understand that XLConnect
can be used to read an Excel worksheet into R. For example, this would read the first worksheet in a workbook called test.xls
into R.
library(XLConnect)
readWorksheetFromFile('test.xls', sheet = 1)
I have an Excel Workbook with multiple worksheets.
How can all worksheets in a workbook be imported into a list in R where each element of the list is a data.frame for a given sheet, and where the name of each element corresponds to the name of the worksheet in Excel?
I stumbled across this old question and I think the easiest approach is still missing.
You can use
rio
to import all excel sheets with just one line of code.If you're a fan of the
tidyverse
, you can easily import them as tibbles by adding thesetclass
argument to the function call.Suppose they have the same format, you could easily row bind them by setting the
rbind
argument toTRUE
.You can load the work book and then use
lapply
,getSheets
andreadWorksheet
and do something like this.To read multiple sheets from a workbook, use readxl package as follows:
Here, bind_row (dplyr) will put all data rows from all sheets into one data frame, and path_to_workbook is "dir/of/the/data/workbook".
Since this is the number one hit to the question: Read multi sheet excel to list:
here is the
openxlsx
solution: