EVOLUTION-MANAGER
Edit File: group_by_all.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Group by a selection of variables</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for group_by_all {dplyr}"><tr><td>group_by_all {dplyr}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Group by a selection of variables</h2> <h3>Description</h3> <a href='https://www.tidyverse.org/lifecycle/#superseded'><img src='figures/lifecycle-superseded.svg' alt='Superseded lifecycle'></a> <p>Scoped verbs (<code style="white-space: pre;">_if</code>, <code style="white-space: pre;">_at</code>, <code style="white-space: pre;">_all</code>) have been superseded by the use of <code><a href="across.html">across()</a></code> in an existing verb. See <code>vignette("colwise")</code> for details. </p> <p>These <a href="scoped.html">scoped</a> variants of <code><a href="group_by.html">group_by()</a></code> group a data frame by a selection of variables. Like <code><a href="group_by.html">group_by()</a></code>, they have optional <a href="mutate.html">mutate</a> semantics. </p> <h3>Usage</h3> <pre> 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) ) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>.tbl</code></td> <td> <p>A <code>tbl</code> object.</p> </td></tr> <tr valign="top"><td><code>.funs</code></td> <td> <p>A function <code>fun</code>, a quosure style lambda <code>~ fun(.)</code> or a list of either form.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments for the function calls in <code>.funs</code>. These are evaluated only once, with <a href="../../rlang/html/dyn-dots.html">tidy dots</a> support.</p> </td></tr> <tr valign="top"><td><code>.add</code></td> <td> <p>See <code><a href="group_by.html">group_by()</a></code></p> </td></tr> <tr valign="top"><td><code>.drop</code></td> <td> <p>Drop groups formed by factor levels that don't appear in the data? The default is <code>TRUE</code> except when <code>.data</code> has been previously grouped with <code>.drop = FALSE</code>. See <code><a href="group_by_drop_default.html">group_by_drop_default()</a></code> for details.</p> </td></tr> <tr valign="top"><td><code>.vars</code></td> <td> <p>A list of columns generated by <code><a href="vars.html">vars()</a></code>, a character vector of column names, a numeric vector of column positions, or <code>NULL</code>.</p> </td></tr> <tr valign="top"><td><code>.predicate</code></td> <td> <p>A predicate function to be applied to the columns or a logical vector. The variables for which <code>.predicate</code> is or returns <code>TRUE</code> are selected. This argument is passed to <code><a href="../../rlang/html/as_function.html">rlang::as_function()</a></code> and thus supports quosure-style lambda functions and strings representing function names.</p> </td></tr> </table> <h3>Grouping variables</h3> <p>Existing grouping variables are maintained, even if not included in the selection. </p> <h3>Examples</h3> <pre> # Group a data frame by all variables: group_by_all(mtcars) # -> mtcars %>% group_by(across()) # Group by variables selected with a predicate: group_by_if(iris, is.factor) # -> iris %>% group_by(across(where(is.factor))) # Group by variables selected by name: group_by_at(mtcars, vars(vs, am)) # -> mtcars %>% group_by(across(c(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)) </pre> <hr /><div style="text-align: center;">[Package <em>dplyr</em> version 1.0.2 <a href="00Index.html">Index</a>]</div> </body></html>