This selection helpers matches grouping variables. It can be used in select() or vars() selections.

group_cols(vars = peek_vars())

Arguments

vars

A character vector of variable names. When called from inside selecting functions like dplyr::select() these are automatically set to the names of the table.

See also

groups() and group_vars() for retrieving the grouping variables outside selection contexts.

Examples

gdf <- iris %>% group_by(Species) # Select the grouping variables: gdf %>% select(group_cols())
#> # A tibble: 150 x 1 #> # Groups: Species [3] #> Species #> <fct> #> 1 setosa #> 2 setosa #> 3 setosa #> 4 setosa #> 5 setosa #> 6 setosa #> 7 setosa #> 8 setosa #> 9 setosa #> 10 setosa #> # … with 140 more rows
# Remove the grouping variables from mutate selections: gdf %>% mutate_at(vars(-group_cols()), `/`, 100)
#> # A tibble: 150 x 5 #> # Groups: Species [3] #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> <dbl> <dbl> <dbl> <dbl> <fct> #> 1 0.051 0.035 0.0140 0.002 setosa #> 2 0.049 0.03 0.0140 0.002 setosa #> 3 0.047 0.032 0.013 0.002 setosa #> 4 0.046 0.031 0.015 0.002 setosa #> 5 0.05 0.036 0.0140 0.002 setosa #> 6 0.054 0.039 0.017 0.004 setosa #> 7 0.046 0.034 0.0140 0.003 setosa #> 8 0.05 0.034 0.015 0.002 setosa #> 9 0.044 0.0290 0.0140 0.002 setosa #> 10 0.049 0.031 0.015 0.001 setosa #> # … with 140 more rows