你需要把你的模特列在一个清单里(
list()
),而不是向量(
c()
):
library(broom)
library(purrr)
model1 <- lm(cyl ~ hp, data = mtcars)
model2 <- lm(mpg ~ cyl, data = mtcars)
list(
model1,
model2
) %>%
map(tidy)
#> [[1]]
#> # A tibble: 2 Ã 5
#> term estimate std.error statistic p.value
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 3.01 0.425 7.07 0.0000000741
#> 2 hp 0.0217 0.00264 8.23 0.00000000348
#>
#> [[2]]
#> # A tibble: 2 Ã 5
#> term estimate std.error statistic p.value
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 37.9 2.07 18.3 8.37e-18
#> 2 cyl -2.88 0.322 -8.92 6.11e-10
于2022年4月10日由
reprex package
(v2.0.1)