【发布时间】:2018-05-15 08:39:57
【问题描述】:
我想在map-调用中使用update-函数更新lm-model,但这会引发以下错误:
mtcars %>% group_by(cyl) %>%
nest() %>%
mutate(lm1 = map(data, ~lm(mpg ~ wt, data = .x)),
lm2 = map(lm1, ~update(object = .x, formula = .~ . + hp)))
Error in mutate_impl(.data, dots) :
Evaluation error: cannot coerce class ""lm"" to a data.frame.
谁能帮我解决这个问题?我对这个错误感到困惑,因为例如这工作得很好:
mtcars %>% group_by(cyl) %>%
nest() %>%
mutate(lm1 = map(data, ~lm(mpg ~ wt, data = .x)),
lm2 = map_dbl(lm1, ~coefficients(.x)[1]))
【问题讨论】: