library(tidyverse)
a = data.frame(c1 = c(1,2,3), c2 = c("a","b","c"))
b = data.frame(c3 = c(TRUE,FALSE,TRUE))
a %>% mutate(c_nested = b)
产生错误:
错误:列
c_nested
的类数据不受支持。框架
如何添加包含嵌套data.frame的列?
非常感谢!
答案 0 :(得分:0)
我们可以将其作为list
列传递
a %>%
mutate(c_nested = list(b))
答案 1 :(得分:0)
res <-
a %>%
`$<-`(c_nested, b)
str(res)
# 'data.frame': 3 obs. of 3 variables:
# $ c1 : num 1 2 3
# $ c2 : Factor w/ 3 levels "a","b","c": 1 2 3
# $ c_nested:'data.frame': 3 obs. of 1 variable:
# ..$ c3: logi TRUE FALSE TRUE