0

I have 40 .csv files, all containing over 30 columns with the first column containing a unique ID variable. I would like to merge them all into a single data frame in R, doing a full outer join by the unique id variable.

ddhll
  • 1
  • 2
    Have you tried the answers posted in this thread? https://stackoverflow.com/questions/8091303/simultaneously-merge-multiple-data-frames-in-a-list – Ronak Shah Sep 28 '20 at 01:15
  • What exactly do you need? [A way to load your 40 csvs](https://stackoverflow.com/questions/11433432/how-to-import-multiple-csv-files-at-once) or a way to combine the dataframes obtained from loading csvs? They are many possible answers depending on how these dataframes are stored (in a list, in separate objects in your global environment, *etc*.). Could you please post a [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) example showing your researchs and your problem. – Paul Sep 28 '20 at 06:20

1 Answers1

0

Load your files into a list of tbls first. Then you could apply purrr::reduce which would sequentially combine two elements to one.

library(purrr)
# instead of pasting you would join your tbls
purrr::reduce(list(1,2,3), ~paste("(", .x, "+", .y, ")"))
#> [1] "( ( 1 + 2 ) + 3 )"
purrr::reduce(list(1,2,3,4), ~paste("(", .x, "+", .y, ")"))
#> [1] "( ( ( 1 + 2 ) + 3 ) + 4 )"

Created on 2020-09-28 by the reprex package (v0.3.0)

smichal
  • 141
  • 4