将Excel工作簿中的所有工作表读入带有data.frames的R列表 [英] Read all worksheets in an Excel workbook into an R list with data.frames
问题描述
我明白,可以使用 XLConnect
将Excel工作表读入R.例如,这将读取名为的工作簿中的第一个工作表test.xls
into R。
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)
我有一个包含多个工作表的Excel工作簿。
I have an Excel Workbook with multiple worksheets.
工作簿中的所有工作表如何导入到R中的列表中,其中列表的每个元素都是给定工作表的数据框架,以及每个元素对应于Excel中工作表的名称?
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?
推荐答案
请注意,大多数XLConnect的函数已经向量化。这意味着您可以使用一个函数调用读取所有工作表,而无需执行明确的向量化:
Note that most of XLConnect's functions are already vectorized. This means that you can read in all worksheets with one function call without having to do explicit vectorization:
require(XLConnect)
wb <- loadWorkbook(system.file("demoFiles/mtcars.xlsx", package = "XLConnect"))
lst = readWorksheet(wb, sheet = getSheets(wb))
使用XLConnect 0.2-0 lst 已经是一个命名列表。
With XLConnect 0.2-0 lst will already be a named list.
这篇关于将Excel工作簿中的所有工作表读入带有data.frames的R列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!