问题描述
我有60个Excel文件.每个文件有8张纸.每个文件的工作表相同,但每个文件的列数不同.
I have 60 Excel files. Each files have 8 sheets. Sheets are same for each files but number of columns are different for each file.
我遇到了不同的帖子,这有助于我导入具有多个工作表的单个excel.但是我不想对60个文件重复此操作.有什么办法可以将所有工作表中的全部60个文件一起导入?
I have come across different post which helped me to import a single excel with a multiple sheet. But I do not want to repeat this for 60 files . Is there any way to import all 60 files with all sheets together?
我碰到过这篇文章 https://it.unt.edu/sites/default/files/importmultipleexcel_l_jds_aug2013. pdf .但是他们在考虑同一列,并合并我不想要的所有内容.我只想导入.
I have came across this articlehttps://it.unt.edu/sites/default/files/importmultipleexcel_l_jds_aug2013.pdf.But there they are considering same columns and merging everything which I do not want. I just want to import.
编辑.
注释中的功能是这样的:
EDIT.
The function in the comment is this:
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
}
mysheets <- read_excel_allsheets("ALL_1_18_2018.xlsx")
推荐答案
您可以像下面这样使用函数read_excel_allsheets
:
You can use your function read_excel_allsheets
like this:
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
}
files <- list.files(path = "/directory/in/question/",
pattern = "*.xlsx",
full.names = TRUE)
out <- lapply(files, read_excel_allsheets)
names(out) <- basename(files)
这篇关于如何在R中导入具有多个工作表的多个Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!