将数据帧列表逐行合并为一个数据帧 [英] Combine a list of data frames into one data frame by row

查看:59
本文介绍了将数据帧列表逐行合并为一个数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个代码,它在一处最终以一个数据帧列表结尾,我真的想将其转换为单个大数据帧.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆