Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

c_across

Combine values from multiple columns


Description

c_across() is designed to work with rowwise() to make it easy to perform row-wise aggregations. It has two differences from c():

  • It uses tidy select semantics so you can easily select multiple variables. See vignette("rowwise") for more details.

  • It uses vctrs::vec_c() in order to give safer outputs.

Usage

c_across(cols = everything())

Arguments

cols

<tidy-select> Columns to transform. Because across() is used within functions like summarise() and mutate(), you can't select or compute upon grouping variables.

See Also

across() for a function that returns a tibble.

Examples

df <- tibble(id = 1:4, w = runif(4), x = runif(4), y = runif(4), z = runif(4))
df %>%
  rowwise() %>%
  mutate(
    sum = sum(c_across(w:z)),
    sd = sd(c_across(w:z))
 )

dplyr

A Grammar of Data Manipulation

v1.0.6
MIT + file LICENSE
Authors
Hadley Wickham [aut, cre] (<https://orcid.org/0000-0003-4757-117X>), Romain François [aut] (<https://orcid.org/0000-0002-2444-4226>), Lionel Henry [aut], Kirill Müller [aut] (<https://orcid.org/0000-0002-1416-3412>), RStudio [cph, fnd]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.