group_cols: Select grouping variables

Description Usage Arguments See Also Examples

View source: R/select-helpers.R

Description

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

Usage

1

Arguments

vars

Deprecated; please use data instead.

data

For advanced use only. The default NULL automatically finds the "current" data frames.

See Also

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

Examples

1
2
3
4
5
6
7
gdf <- iris %>% group_by(Species)
gdf %>% select(group_cols())

# Remove the grouping variables from mutate selections:
gdf %>% mutate_at(vars(-group_cols()), `/`, 100)
# -> No longer necessary with across()
gdf %>% mutate(across(everything(), ~ . / 100))

Example output

Attaching package:dplyrThe following objects are masked frompackage:stats:

    filter, lag

The following objects are masked frompackage:base:

    intersect, setdiff, setequal, union

# 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
# 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
# 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

dplyr documentation built on June 19, 2021, 1:07 a.m.