How to get summary statistics by group

前端 未结 10 1358
渐次进展
渐次进展 2020-11-22 05:13

I\'m trying to get multiple summary statistics in R/S-PLUS grouped by categorical column in one shot. I found couple of functions, but all of them do one statistic per call,

10条回答
  •  再見小時候
    2020-11-22 05:28

    dplyr package could be nice alternative to this problem:

    library(dplyr)
    
    df %>% 
      group_by(group) %>% 
      summarize(mean = mean(dt),
                sum = sum(dt))
    

    To get 1st quadrant and 3rd quadrant

    df %>% 
      group_by(group) %>% 
      summarize(q1 = quantile(dt, 0.25),
                q3 = quantile(dt, 0.75))
    

提交回复
热议问题