0

If I have different dataframes with the same columns names what kind of bind/merge should I implement.

Example df1:

stock,price
stockA, 2
stockB, 10

Example of df2:

stock, price
stockC, 3

Example of df3:

stock,price
stockJ, 33

Merged

 stock,price
    stockA, 2
    stockB, 10
    stockC, 3
    stockJ, 33
Mati
  • 23
  • 4

1 Answers1

-1

I recommend bind_rows from dplyr -- it will handle aligning columns in case there are slight differences. It also handles lists, which may make it easier to handle cases created by lapply or split

Example:

bind_rows(df1, df2, df3)

You can also easily track which data.frame they came from using the .id argument:

bind_rows(df1 = df1, df2 = df2, df3 = df3, .id = "whichDF")
Mark Peterson
  • 9,370
  • 2
  • 25
  • 48