【发布时间】:2020-11-02 12:29:41
【问题描述】:
我有一个要转换为数据框的向量列表。
代码
a <- list( c(1,2,3,4),
c(1,2,3,4),
c(4,5,6,3),
c(6,3,2,6))
在this post 的帮助下,我能够通过以下方式做到这一点:
library(tidyverse)
a %>%
reduce(rbind) %>%
as.data.frame()
> a %>% reduce(rbind) %>% as.data.frame()
V1 V2 V3 V4
out 1 2 3 4
elt 1 2 3 4
elt.1 4 5 6 3
elt.2 6 3 2 6
我想使用purrr的bind_rows()函数(a %>% bind_rows),因为它看起来更方便。但是,这会产生错误:
错误:参数 1 必须有名称。
问题
- 这里发生了什么?
- 我怎样才能防止它发生;)?
【问题讨论】:
-
可能基数:
do.call(rbind, a) -
bind_rows()最初是一个dplyr函数,旨在将data.frames 或tibbles 绑定在一起。由于data.frame列有名称,bind_rows期望输入被命名,这就是你得到错误的原因。rbind在这里不那么严格。