0

I managed to import multiple xlsx files using this tip(How can I read multiple (excel) files into R?), but now I would like to merge all these imported data.frames into a single data.frame.

All xlsx files have the same header but are from different years. I would like to string them together so that the header works for everyone.

Example part:

df 1

enter image description here

df2

enter image description here

I hope this:

enter image description here

to import all the data.frame I used the code:

library(readxl)
library(dplyr)

    setwd('D:/01-Mestrado/0Dissertacacao/1Rstudio/classes_novo')
    
    file.list <- list.files(pattern='*.xlsx')
    df.list <- lapply(file.list, read_excel)
    
    View(df.list)
wesleysc352
  • 579
  • 1
  • 8
  • 21
  • 2
    Do you need `do.call(rbind, df.list)` ? – Ronak Shah Jun 11 '21 at 01:57
  • @RonakShah how would the output look like? why would `do.call(rbind, df.list)` generate a new data.frame? – wesleysc352 Jun 11 '21 at 02:01
  • 1
    `purrr::reduce(df.list, rbind)` – jpdugo17 Jun 11 '21 at 02:02
  • I get it now, i added a new variable `df_final<-do.call(rbind, df.list) `and it worked – wesleysc352 Jun 11 '21 at 02:08
  • 1
    @wesleysc352 ... because there is an `rbind.data.frame` function. It does not need to have `purrr::reduce`. It is already capable of taking an arbitrary number of dataframes. (And when you get a single line comment instead of an answer, it generally means the question has been recognized by an experienced reader that it is one that has been asked and answered many times already.) – IRTFM Jun 11 '21 at 02:10

0 Answers0