How to add a column using the mapping vector after purrr::map_df

余生长醉 提交于 2019-12-04 10:25:48

Using set_names should do it

cyls %>% 
  set_names() %>% 
  map_df(., ~tidy(lm(hp~wt,data=mtcars %>% filter(cyl == .x))), .id = "cyls")

  cyls        term   estimate std.error   statistic
1    4 (Intercept)  69.204726  28.41355  2.43562436
2    4          wt   5.876308  12.09420  0.48587823
3    6 (Intercept) 187.273314  90.85245  2.06129062
4    6          wt -20.848451  28.98418 -0.71930440
5    8 (Intercept) 204.484626  78.77132  2.59592744
6    8          wt   1.182647  19.37501  0.06103983
     p.value
1 0.03763378
2 0.63866393
3 0.09427827
4 0.50415924
5 0.02340090
6 0.95233233
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!