此问题已在此处有答案:
Add the index of list to bind_rows?(2个答案)
Create a column based on the name of the element list that contain the data frame in R(2个答案)
Not getting list names as row names in do.call [duplicate](2个答案)
Adding a column to every dataframe in a list with the name of the list element(2个答案)
6天前关闭。
在执行拆分和回归之后,我想将这些列表合并到一个 Dataframe 中,并将列表名称作为行名称。任何建议。
lapply(split(mtcars, mtcars$cyl), \(x) lm(mpg ~ disp, data = x)) |>
lapply(\(x) broom::tidy(x))
#> $`4`
#> # A tibble: 2 × 5
#> term estimate std.error statistic p.value
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 40.9 3.59 11.4 0.00000120
#> 2 disp -0.135 0.0332 -4.07 0.00278
#>
#> $`6`
#> # A tibble: 2 × 5
#> term estimate std.error statistic p.value
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 19.1 2.91 6.55 0.00124
#> 2 disp 0.00361 0.0156 0.232 0.826
#>
#> $`8`
#> # A tibble: 2 × 5
#> term estimate std.error statistic p.value
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 22.0 3.35 6.59 0.0000259
#> 2 disp -0.0196 0.00932 -2.11 0.0568
所需输出:
cyl term estimate std.error statistic p.value
<dbl> <chr> <dbl> <dbl> <dbl> <dbl>
1 6 (Intercept) 19.1 2.91 6.55 0.00124
2 6 disp 0.00361 0.0156 0.232 0.826
3 4 (Intercept) 40.9 3.59 11.4 0.00000120
4 4 disp -0.135 0.0332 -4.07 0.00278
5 8 (Intercept) 22.0 3.35 6.59 0.0000259
6 8 disp -0.0196 0.00932 -2.11 0.0568
创建于2023-04-27带有reprex v2.0.2
1条答案
按热度按时间q8l4jmvw1#
试试
data.table::rbindlist
它给出了