【发布时间】:2021-06-12 23:34:17
【问题描述】:
我有一个由 10 列组成的数据框,其中一个是另一个数据框,是 rowwise() 操作的结果。
类似这样的东西(只是一个例子,column2 是一个不在列表中的数据框):
id column1 column2
1213 a df
2234 b df
4565 c df
class(df$column2)
[1] "data.frame"
因此,数据按行分组(请参阅 tidyverse 站点中的 rowwise()),问题是我想提取 column2 数据帧并将其放在其余列之外。因为它们具有相同的行数。
通常的 tidyr::unnest() 方法会出错:
unnest(c, cols = c(column2))
Error: Assigned data `map(data[[col]], as_df, col = col)` must be compatible with existing data.
x Existing data has 24356 rows.
x Assigned data has 124 rows.
i Only vectors of size 1 are recycled.
所以我已将 column2 提取到另一个数据帧中,然后 dplyr::bind_cols() 但这很脏,我想是否有更清洁的方法。
【问题讨论】: