EVOLUTION-MANAGER
Edit File: everything.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: Select all variables or the last variable</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 everything {tidyselect}"><tr><td>everything {tidyselect}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Select all variables or the last variable</h2> <h3>Description</h3> <p>These functions are <a href="language.html">selection helpers</a>. </p> <ul> <li> <p><code><a href="everything.html">everything()</a></code> selects all variable. It is also useful in combination with other tidyselect operators. </p> </li> <li> <p><code><a href="everything.html">last_col()</a></code> selects the last variable. </p> </li></ul> <h3>Usage</h3> <pre> everything(vars = NULL) last_col(offset = 0L, vars = NULL) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>vars</code></td> <td> <p>A character vector of variable names. If not supplied, the variables are taken from the current selection context (as established by functions like <code>select()</code> or <code>pivot_longer()</code>).</p> </td></tr> <tr valign="top"><td><code>offset</code></td> <td> <p>Set it to <code>n</code> to select the nth var from the end.</p> </td></tr> </table> <h3>Examples</h3> <p>Selection helpers can be used in functions like <code>dplyr::select()</code> or <code>tidyr::pivot_longer()</code>. Let's first attach the tidyverse:<div class="r"></p> <pre>library(tidyverse) # For better printing iris <- as_tibble(iris) mtcars <- as_tibble(mtcars) </pre></div> <p>Use <code>everything()</code> to select all variables:<div class="r"></p> <pre>iris %>% select(everything()) #> # A tibble: 150 x 5 #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> <dbl> <dbl> <dbl> <dbl> <fct> #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> # ... with 146 more rows mtcars %>% pivot_longer(everything()) #> # A tibble: 352 x 2 #> name value #> <chr> <dbl> #> 1 mpg 21 #> 2 cyl 6 #> 3 disp 160 #> 4 hp 110 #> # ... with 348 more rows </pre></div> <p>Use <code>last_col()</code> to select the last variable:<div class="r"></p> <pre>iris %>% select(last_col()) #> # A tibble: 150 x 1 #> Species #> <fct> #> 1 setosa #> 2 setosa #> 3 setosa #> 4 setosa #> # ... with 146 more rows mtcars %>% pivot_longer(last_col()) #> # A tibble: 32 x 12 #> mpg cyl disp hp drat wt qsec vs am gear name value #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <chr> <dbl> #> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 carb 4 #> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 carb 4 #> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 carb 1 #> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 carb 1 #> # ... with 28 more rows </pre></div> <p>Supply an offset <code>n</code> to select a variable located <code>n</code> positions from the end:<div class="r"></p> <pre>mtcars %>% select(1:last_col(5)) #> # A tibble: 32 x 6 #> mpg cyl disp hp drat wt #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 21 6 160 110 3.9 2.62 #> 2 21 6 160 110 3.9 2.88 #> 3 22.8 4 108 93 3.85 2.32 #> 4 21.4 6 258 110 3.08 3.22 #> # ... with 28 more rows </pre></div> <h3>See Also</h3> <p>The <a href="language.html">selection language</a> page, which includes links to other selection helpers. </p> <hr /><div style="text-align: center;">[Package <em>tidyselect</em> version 1.1.0 <a href="00Index.html">Index</a>]</div> </body></html>