summarize_multi: multi-level summarize function

Description Usage Arguments Note Examples

Description

This function is used identically to dplyr::summarize. However, it applies the grouping variables of .data additively and returns summary values at each level. The returned dataset contains an additional variable 'level' that tracks the number of grouping variables applied. Note that the function additively applies grouping variables in the order that they were originally specified. It does not do combinations of levels. In other words, a dataset with three grouping variables, 'a', 'b', and 'c', would return level 0: ungroup(), level 1: group_by('a'), level 2: group_by ('a', 'b') and level 3: group_by('a', 'b', 'c')

Usage

1
summarize_multi(.data, ..., level = "level_")

Arguments

.data

the data frame to be summarised

...

further arguments of the form var = value

level

name of created variable tracking summary levels. Default is 'level_'

Note

by default this function creates a variable called "level_" that tracks the levels of the groupings. If this conflicts with your dataset it can be renamed using the level parameter.

Examples

1
2
3
summarize_multi(iris, mean_sepal = mean(Sepal.Length))
summarize_multi(iris %>% dplyr::group_by(Species), mean_sepal = mean(Sepal.Length))
summarize_multi(iris %>% dplyr::group_by(Species, Petal.Width), mean_sepal = mean(Sepal.Length))

williamlief/liefTools documentation built on Jan. 1, 2020, 6:48 p.m.