Add margin row totals in dplyr chain

后端 未结 7 2155
一整个雨季
一整个雨季 2020-12-05 00:25

I would like to add overall summary rows while also calculating summaries by group using dplyr. I have found various questions asking how to do this, e.g. here, here, and he

7条回答
  •  遥遥无期
    2020-12-05 01:15

    If you would like to have truly universal solution you could use a combination of purrr::map_df, base::c and base::sum mtcars %>% purrr::map_df(~c(.x, sum(.x, na.rm=TRUE))) %>% tail

    P.S. All columns must be numeric!

提交回复
热议问题