如何连接不同长度的数据帧列表?

时间:2017-11-21 23:08:41

标签: r dataframe

我有一个数据框列表,列数相同,但每个数据框中的行数不同。如何将所有行连接成一个数据框?

require('jsonlite')

# Get the list of repos for each of these GitHub user
users <- c('hadley', 'schmidt4brains', 'fred')
urls <- lapply(users, function(user) paste0("https://api.github.com/users/", user, "/repos"))

# Fetch all the repos from all users.
# Now we have a list of 3 data frames: same columns, but different row counts
repo_list <- lapply(urls, fromJSON)

如何将所有数据帧中的所有行合并为一个数据框?

sapply(repo_list, identity)组合了所有行,但结果不是数据框,并且丢失了所有列名称。

2 个答案:

答案 0 :(得分:2)

repos <- rbind_pages(repo_list)可以解决问题。

当然,在搜索StackOverflow几个小时之后,尝试了二十种不同的失败方法,并且在格式上找到一个可以证明我的问题的问题,我在发布后15分钟找到了自己的答案!

答案 1 :(得分:-1)

...替代地

library(dplyr)
bind_rows(repo_list)

http://dplyr.tidyverse.org/reference/bind.html

相关问题