描述

    将一组值总结为每个组的一个值。如果只有一个组,那么将只返回一个值。summarise函数应该总是返回一个值。

    聚合统计 - 图1

    1. iris %>% summarise_dt(avg = mean(Sepal.Length))
    2. iris %>% summarise_dt(avg = mean(Sepal.Length),by = Species)
    3. mtcars %>% summarise_dt(avg = mean(hp),by = .(cyl,vs))
    4. # the data.table way
    5. mtcars %>% summarise_dt(cyl_n = .N, by = .(cyl, vs)) # `.` is short for list
    6. iris %>% summarise_vars(is.numeric,min)
    7. iris %>% summarise_vars(-is.factor,min)
    8. iris %>% summarise_vars(1:4,min)
    9. iris %>% summarise_vars(is.numeric,min,by ="Species")
    10. mtcars %>% summarise_vars(is.numeric,mean,by = "vs,am")