Reputation: 175
I have many data frames and I want to merge them to make one large data frame
For example, I have:
month day time h
1 1 23 112
1 2 34 143
1 3 54 352
and
month day time h
2 1 42 133
2 2 31 342
2 3 55 333
They all have the same column names and I want to add them together so that the months are in ascending order in a big data frame of about 60 months.
I'm thinking x<-do.call("cbind",dataframes)
would do it. But when I try to call head(x)
to check the data it says Error in head(x) : object 'x' not found
Is there a better way to merge/combine these data frames?
I want the output data frame to look like
month day time h
1 1 23 112
1 2 34 143
1 3 54 352
...
2 1 42 133
2 2 31 342
2 3 55 333
Upvotes: 2
Views: 59
Reputation: 886938
We can use rbind
instead of cbind
.
do.call(rbind, lst)
Or if we are using data.table
, we can do
library(data.table)
rbindlist(lst)
Or with dplyr
library(dplyr)
bind_rows(lst)
where 'lst' is the list
of 'data.frame'
Upvotes: 3