How to import multiple excel files with multiple sheet in r

前端 未结 1 1459
礼貌的吻别
礼貌的吻别 2021-01-16 16:24

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.

I have come across different post

1条回答
  •  借酒劲吻你
    2021-01-16 16:45

    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)
    

    0 讨论(0)
提交回复
热议问题