View source: R/colwise-group-by.R
group_by_all | R Documentation |
Scoped verbs (_if
, _at
, _all
) have been superseded by the use of
pick()
or across()
in an existing verb. See vignette("colwise")
for
details.
These scoped variants of group_by()
group a data frame by a
selection of variables. Like group_by()
, they have optional
mutate semantics.
group_by_all(
.tbl,
.funs = list(),
...,
.add = FALSE,
.drop = group_by_drop_default(.tbl)
)
group_by_at(
.tbl,
.vars,
.funs = list(),
...,
.add = FALSE,
.drop = group_by_drop_default(.tbl)
)
group_by_if(
.tbl,
.predicate,
.funs = list(),
...,
.add = FALSE,
.drop = group_by_drop_default(.tbl)
)
.tbl |
A |
.funs |
A function |
... |
Additional arguments for the function calls in
|
.add |
See |
.drop |
Drop groups formed by factor levels that don't appear in the
data? The default is |
.vars |
A list of columns generated by |
.predicate |
A predicate function to be applied to the columns
or a logical vector. The variables for which |
Existing grouping variables are maintained, even if not included in the selection.
# Group a data frame by all variables:
group_by_all(mtcars)
# ->
mtcars %>% group_by(pick(everything()))
# Group by variables selected with a predicate:
group_by_if(iris, is.factor)
# ->
iris %>% group_by(pick(where(is.factor)))
# Group by variables selected by name:
group_by_at(mtcars, vars(vs, am))
# ->
mtcars %>% group_by(pick(vs, am))
# Like group_by(), the scoped variants have optional mutate
# semantics. This provide a shortcut for group_by() + mutate():
d <- tibble(x=c(1,1,2,2), y=c(1,2,1,2))
group_by_all(d, as.factor)
# ->
d %>% group_by(across(everything(), as.factor))
group_by_if(iris, is.factor, as.character)
# ->
iris %>% group_by(across(where(is.factor), as.character))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.