我还是比较喜欢 Base R 风格,过程简单清晰,便于 Debug
# 拆分
mtcars_cyl <- split(mtcars, mtcars$cyl)
# 计算
mtcars_fit <- lapply(mtcars_cyl, lm, formula = mpg ~ disp)
mtcars_coef <- lapply(mtcars_fit, coef)
# 合并
dat <- do.call("rbind", mtcars_coef)
> dat
(Intercept) disp
4 40.87 -0.135142
6 19.08 0.003605
8 22.03 -0.019634