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 = "._.")
Data frame with result of grouped summary.
A selection of grouping columns (as in tidyr::unite()
).
A string to be used as separator of grouping levels.
A string to be used as separator in column pack.
A data frame in column pack format.
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.
mtcars_grouped_summary <- mtcars %>%
dplyr::group_by(vs, am) %>%
dplyr::summarise(n_low = dplyr::n() > 6, n_high = dplyr::n() < 10)
#> `summarise()` has grouped output by 'vs'. You can override using the `.groups`
#> argument.
spread_groups(mtcars_grouped_summary, vs, am)
#> # A tibble: 1 × 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
#> # ℹ 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 × 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
#> # ℹ 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 × 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
#> # ℹ 3 more variables: `0.1__n_high` <lgl>, `1.0__n_high` <lgl>,
#> # `1.1__n_high` <lgl>