1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/colwise-group-by.R
3\name{group_by_all}
4\alias{group_by_all}
5\alias{group_by_at}
6\alias{group_by_if}
7\title{Group by a selection of variables}
8\usage{
9group_by_all(
10  .tbl,
11  .funs = list(),
12  ...,
13  .add = FALSE,
14  .drop = group_by_drop_default(.tbl)
15)
16
17group_by_at(
18  .tbl,
19  .vars,
20  .funs = list(),
21  ...,
22  .add = FALSE,
23  .drop = group_by_drop_default(.tbl)
24)
25
26group_by_if(
27  .tbl,
28  .predicate,
29  .funs = list(),
30  ...,
31  .add = FALSE,
32  .drop = group_by_drop_default(.tbl)
33)
34}
35\arguments{
36\item{.tbl}{A \code{tbl} object.}
37
38\item{.funs}{A function \code{fun}, a quosure style lambda \code{~ fun(.)} or a list of either form.}
39
40\item{...}{Additional arguments for the function calls in
41\code{.funs}. These are evaluated only once, with \link[rlang:dyn-dots]{tidy dots} support.}
42
43\item{.add}{See \code{\link[=group_by]{group_by()}}}
44
45\item{.drop}{Drop groups formed by factor levels that don't appear in the
46data? The default is \code{TRUE} except when \code{.data} has been previously
47grouped with \code{.drop = FALSE}. See \code{\link[=group_by_drop_default]{group_by_drop_default()}} for details.}
48
49\item{.vars}{A list of columns generated by \code{\link[=vars]{vars()}},
50a character vector of column names, a numeric vector of column
51positions, or \code{NULL}.}
52
53\item{.predicate}{A predicate function to be applied to the columns
54or a logical vector. The variables for which \code{.predicate} is or
55returns \code{TRUE} are selected. This argument is passed to
56\code{\link[rlang:as_function]{rlang::as_function()}} and thus supports quosure-style lambda
57functions and strings representing function names.}
58}
59\description{
60\Sexpr[results=rd, stage=render]{lifecycle::badge("superseded")}
61
62Scoped verbs (\verb{_if}, \verb{_at}, \verb{_all}) have been superseded by the use of
63\code{\link[=across]{across()}} in an existing verb. See \code{vignette("colwise")} for details.
64
65These \link{scoped} variants of \code{\link[=group_by]{group_by()}} group a data frame by a
66selection of variables. Like \code{\link[=group_by]{group_by()}}, they have optional
67\link{mutate} semantics.
68}
69\section{Grouping variables}{
70
71
72Existing grouping variables are maintained, even if not included in
73the selection.
74}
75
76\examples{
77# Group a data frame by all variables:
78group_by_all(mtcars)
79# ->
80mtcars \%>\% group_by(across())
81
82# Group by variables selected with a predicate:
83group_by_if(iris, is.factor)
84# ->
85iris \%>\% group_by(across(where(is.factor)))
86
87# Group by variables selected by name:
88group_by_at(mtcars, vars(vs, am))
89# ->
90mtcars \%>\% group_by(across(c(vs, am)))
91
92# Like group_by(), the scoped variants have optional mutate
93# semantics. This provide a shortcut for group_by() + mutate():
94d <- tibble(x=c(1,1,2,2), y=c(1,2,1,2))
95group_by_all(d, as.factor)
96# ->
97d \%>\% group_by(across(everything(), as.factor))
98
99group_by_if(iris, is.factor, as.character)
100# ->
101iris \%>\% group_by(across(where(is.factor), as.character))
102}
103