将多张图纸导入R中的多个数据帧

将多张图纸导入R中的多个数据帧,r,import-from-excel,R,Import From Excel,我有一个包含大量工作表的Excel文件,我需要一个代码将每个工作表导入到一个单独的数据框中,该数据框的命名方式与Excel中的工作表名称相同 例如,选项卡A、B、C将分别作为数据框A、B和C导入 从其他线程中,我看到了如下代码: length(excel\u sheets(filename))获取文件中的页数 然后创建包含每个选项卡的列表: read_excel_allsheets <- function(filename) { sheets <- readxl::excel_s

我有一个包含大量工作表的Excel文件,我需要一个代码将每个工作表导入到一个单独的数据框中,该数据框的命名方式与Excel中的工作表名称相同

例如,选项卡A、B、C将分别作为数据框A、B和C导入

从其他线程中,我看到了如下代码:
length(excel\u sheets(filename))
获取文件中的页数

然后创建包含每个选项卡的列表:

read_excel_allsheets <- function(filename) {
  sheets <- readxl::excel_sheets(filename)
  x <-    lapply(sheets, function(X) readxl::read_excel(filename, sheet = X))
  names(x) <- sheets
  x
}

read\u excel\u allsheets这里有一种方法:

# write test data
tf <- writexl::write_xlsx(
  list("the mtcars" = mtcars, "iris data" = iris), 
  tempfile(fileext = ".xlsx")
)

# read excel sheets
sheets <- readxl::excel_sheets(tf)
lst <- lapply(sheets, function(sheet) 
  readxl::read_excel(tf, sheet = sheet)
)
names(lst) <- sheets

# shove them into global environment
list2env(lst, envir = .GlobalEnv)
#编写测试数据

tf函数读入所有选项卡并将它们保存为单个列表的元素(因为
lappy()
)。您可以使用
list2env
从列表中取出元素:

your_excel_list <- read_excel_allsheets("test.xlsx")
list2env(your_excel_list, .GlobalEnv)
您的excel列表可以一行读取。
应加载magrittr和dplyr包

data <- lapply(list.files(pattern = "*.xlsx"),function(x) x=read_excel(x,sheet = "(sheetname)")) %>%  bind_rows 
数据%bind\u行