Function that is used during interpretation of group pack output. It converts grouped summary into column pack format.

spread_groups(.tbl, ..., .group_sep = ".", .col_sep = "._.")

Arguments

.tbl

Data frame with result of grouped summary.

...

A selection of grouping columns (as in tidyr::unite()).

.group_sep

A string to be used as separator of grouping levels.

.col_sep

A string to be used as separator in column pack.

Value

A data frame in column pack format.

Details

Multiple grouping variables are converted to one with tidyr::unite() and separator .group_sep. New values are then treated as variable names which should be validated and which represent the group data as a whole.

Examples

mtcars_grouped_summary <- mtcars %>% dplyr::group_by(vs, am) %>% dplyr::summarise(n_low = dplyr::n() > 6, n_high = dplyr::n() < 10)
#> `summarise()` regrouping output by 'vs' (override with `.groups` argument)
spread_groups(mtcars_grouped_summary, vs, am)
#> # A tibble: 1 x 8 #> `0.0._.n_low` `0.1._.n_low` `1.0._.n_low` `1.1._.n_low` `0.0._.n_high` #> <lgl> <lgl> <lgl> <lgl> <lgl> #> 1 TRUE FALSE TRUE TRUE FALSE #> # … with 3 more variables: `0.1._.n_high` <lgl>, `1.0._.n_high` <lgl>, #> # `1.1._.n_high` <lgl>
spread_groups(mtcars_grouped_summary, vs, am, .group_sep = "__")
#> # A tibble: 1 x 8 #> `0__0._.n_low` `0__1._.n_low` `1__0._.n_low` `1__1._.n_low` `0__0._.n_high` #> <lgl> <lgl> <lgl> <lgl> <lgl> #> 1 TRUE FALSE TRUE TRUE FALSE #> # … with 3 more variables: `0__1._.n_high` <lgl>, `1__0._.n_high` <lgl>, #> # `1__1._.n_high` <lgl>
spread_groups(mtcars_grouped_summary, vs, am, .col_sep = "__")
#> # A tibble: 1 x 8 #> `0.0__n_low` `0.1__n_low` `1.0__n_low` `1.1__n_low` `0.0__n_high` #> <lgl> <lgl> <lgl> <lgl> <lgl> #> 1 TRUE FALSE TRUE TRUE FALSE #> # … with 3 more variables: `0.1__n_high` <lgl>, `1.0__n_high` <lgl>, #> # `1.1__n_high` <lgl>