将数据框列表逐行合并为一个数据框 [英] Combine a list of data frames into one data frame by row
本文介绍了将数据框列表逐行合并为一个数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码在一个地方以一列数据框结束,我真的想将其转换为单个大数据框.
I have code that at one place ends up with a list of data frames which I really want to convert to a single big data frame.
我从一个之前的问题中得到了一些提示,该问题正在尝试做一些类似但更复杂的事情.
I got some pointers from an earlier question which was trying to do something similar but more complex.
这是我开始的一个例子(为了说明,这是非常简化的):
Here's an example of what I am starting with (this is grossly simplified for illustration):
listOfDataFrames <- vector(mode = "list", length = 100)
for (i in 1:100) {
listOfDataFrames[[i]] <- data.frame(a=sample(letters, 500, rep=T),
b=rnorm(500), c=rnorm(500))
}
我目前正在使用这个:
df <- do.call("rbind", listOfDataFrames)
推荐答案
使用 dplyr 包中的 bind_rows()
:
bind_rows(list_of_dataframes, .id = "column_label")
这篇关于将数据框列表逐行合并为一个数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文