Reputation: 41
Looking for a way to read in multiple xlsx files from a folder at one time in a way that loads each individual sheet in each file into a separate data frame. Most solutions I've found such as purrr::map_df/purrr::map_dfr seem to be geared towards stitching them together into one df at once.
For context: while I do intend to eventually stitch these files together into one df, there's a fair amount of munging specific to each tab needed first before doing so.
Upvotes: 0
Views: 328
Reputation: 1237
You could use map
in place of lapply
if you want to use purrr
:
files <- list.files(pattern = "^.*\\.xlsx$")
dfs <- lapply(files,
\(x) {
sheets <- readxl::excel_sheets(x)
output <- lapply(sheets,
\(y) readxl::read_xlsx(x, sheet = y))
setNames(output, sheets)
})
Upvotes: 1