Search code examples
rmergedplyrconcatenationrbind

How do I vertically join or merge multiple datasets within R


I have 12 datasets that all resemble this (this is a sample, the real datasets all contain over 10,000 varying rows, with the same number/name of columns)

   df1

   Start                End                      Duration

   9/10/2019 1:00:00  PM  9/10/2019 1:00:10  PM   10
   10/10/2019 2:00:00 PM 10/10/2019 2:00:10  PM   10


   df2

   Start                End                        Duration

   11/10/2019 1:00:00 AM  11/10/2019 1:00:10  AM   10
   12/10/2019 2:00:00 AM  12/10/2019 2:00:10  AM   10


    df3

   Start                   End                   Duration

   01/10/2020 1:00:00 AM   01/10/2020 1:00:10 AM   10
   02/10/2020 2:00:00 AM   02/10/2020 2:00:10 AM   10

I would like this outcome:

   Start                     End                   Duration

   9/10/2019  1:00:00 PM    9/10/2019 1:00:10  PM   10
   10/10/2019 2:00:00 PM    10/10/2019 2:00:10 PM   10
   11/10/2019 1:00:00 AM    11/10/2019 1:00:10 AM   10
   12/10/2019 2:00:00 AM    12/10/2019 2:00:10 AM   10
   01/10/2020 1:00:00 AM    01/10/2020 1:00:10 AM   10
   02/10/2019 2:00:00 AM    02/10/2019 2:00:10 AM   10

Here is my dput:

 structure(list(Start = structure(1:2, .Label = c("11/10/2019 13:00", 
 "12/10/2019 14:00"), class = "factor"), End = structure(1:2, .Label = c("11/10/2019 13:00", 
 "12/10/2019 14:00"), class = "factor"), Duration = c(10L, 10L
 )), class = "data.frame", row.names = c(NA, -2L))



 structure(list(Start = structure(1:2, .Label = c("11/10/2019 1:00:00 AM", 
 "12/10/2019 2:00:00 AM"), class = "factor"), End = structure(1:2, .Label = c("11/10/2019 1:00:10 AM", 
"12/10/2019 2:00:10 AM"), class = "factor"), Duration = c(10L, 
 10L)), class = "data.frame", row.names = c(NA, -2L))


 structure(list(Start = structure(1:2, .Label = c("1/10/2020 1:00:00 AM", 
 "2/10/2020 2:00:00 AM"), class = "factor"), End = structure(1:2, .Label =     c("1/10/2020 1:00:10 AM", 
 "2/10/2020 2:00:10 AM"), class = "factor"), Duration = c(10L, 
 10L)), class = "data.frame", row.names = c(NA, -2L))

This is what I have tried:

  combined <- rbind(df1, df2)

However, it only works when joining 2 datasets and not 10


Solution

  • You can use the bind_rows trom the tidyverse

    library(tidyverse)
    dim(mtcars) # [1] 32 11
    BindMtcars <- bind_rows(mtcars, mtcars, mtcars, mtcars)
    dim(BindMtcars) # [1] 128  11