Group by multiple columns and sum other multiple columns

后端 未结 7 688
孤城傲影
孤城傲影 2020-11-22 07:35

I have a data frame with about 200 columns, out of them I want to group the table by first 10 or so which are factors and sum the rest of the columns.

I have list of

7条回答
  •  佛祖请我去吃肉
    2020-11-22 08:16

    Another way to do this with dplyr that would be generic (don't need list of columns) would be:

    df %>% group_by_if(is.factor) %>% summarize_if(is.numeric,sum,na.rm = TRUE)
    

提交回复
热议问题