library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 3.6.3
#> Warning: package 'ggplot2' was built under R version 3.6.3
#> Warning: package 'tidyr' was built under R version 3.6.3
#> Warning: package 'purrr' was built under R version 3.6.3
#> Warning: package 'dplyr' was built under R version 3.6.3
#> Warning: package 'stringr' was built under R version 3.6.3
#> Warning: package 'forcats' was built under R version 3.6.3
mtcars = as_tibble(mtcars)
cars_nested = mtcars %>% group_by(cyl) %>% nest()
cars_fitted = cars_nested %>%
mutate(fit = map(data, function(x) lm(mpg ~ disp, data = x)))
由reprex 包(v0.3.0)于 2020 年 7 月 29 日创建
当我在 Rstudio 中运行此代码时,我收到以下错误。有什么帮助吗?
> mtcars = as_tibble(mtcars)
> cars_nested = mtcars %>% group_by(cyl) %>% nest()
> cars_fitted = cars_nested %>%
+ mutate(fit = map(data, function(x) lm(mpg ~ disp, data = x)))
Error: Problem with `mutate()` input `fit`.
x object 'disp' not found
i Input `fit` is `map(data, function(x) lm(mpg ~ disp, data = x))`.
i The error occured in group 1: cyl = 4.
Run `rlang::last_error()` to see where the error occurred. ```