1

I have several excel files in one folder. All share the same structure, with the same number of columns and column headings. I know how to import each of these files separately and then combine them using bind_rows() like this:

df1 <- read_excel(excel1.xlsx)
df2 <- read_excel(excel2.xlsx)
df3 <- read_excel(excel3.xlsx)

combined <- bind_rows(df1, df2, df3)

But obviously, this is a lot of typing, and it's an inefficient method if I'm dealing with dozens of excel files. Is there a way to tell R to import all the files from a specific folder, then combine them into one table?

1 Answers1

2

Here what I like to do in this type of situation:

  purrr::map_df(
    .x = list.files(pattern = ".xlsx"),
    .f = read_excel,
    .id = "source"
    )
Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32