合并R中的许多不同数据帧

时间:2015-10-22 05:27:53

标签: r dataframe

我有很多数据框,我想将它们合并成一个大数据框

例如,我有:

month  day  time  h
1      1    23    112
1      2    34    143
1      3    54    352

month  day  time  h
2      1    42    133
2      2    31    342
2      3    55    333

它们都具有相同的列名称,我想将它们添加到一起,以便在大约60个月的大数据框架中按月升序。 我在想x<-do.call("cbind",dataframes)会做到这一点。但是,当我尝试拨打head(x)来查看数据Error in head(x) : object 'x' not found

有没有更好的方法来合并/组合这些数据框?

我希望输出数据框看起来像

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

1 个答案:

答案 0 :(得分:3)

我们可以使用rbind代替cbind

do.call(rbind, lst)

或者如果我们使用data.table,我们可以

library(data.table)
rbindlist(lst)

dplyr

library(dplyr)
bind_rows(lst)

其中&#39; lst&#39;是&#39; data.frame&#39;

list
相关问题