似乎对于存储在列表列中的某些对象,
但是这个确实可以。
dplyr::mutate
只能一次性地对它们进行操作。也就是说,连续两次使用mutate
会导致错误。library(dplyr)
one_mod <- data.frame(grp = "a", x = runif(5,0,1)) %>%
tbl_df %>%
mutate(y = rnorm(x,x*2,1)) %>%
group_by(grp) %>%
do(mod = lm(y~x,data = .))
这种方法行不通:
one_mod %>%
mutate(rsq = summary(mod)$r.squared) %>%
mutate(aic = AIC(mod))
# Error: unsupported type for column 'mod' (VECSXP)
但是这个确实可以。
one_mod %>%
mutate(rsq = summary(mod)$r.squared,
aic = AIC(mod))
#Source: local data frame [1 x 4]
#Groups: grp
#
# grp mod rsq aic
#1 a <S3:lm> 0.6615589 10.63317