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.

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))
 )
#> # A tibble: 4 × 7
#> # Rowwise: 
#>      id     w      x     y     z   sum     sd
#>   <int> <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl>
#> 1     1 0.953 0.0437 0.195 0.529  1.72 0.403 
#> 2     2 0.206 0.502  0.991 0.633  2.33 0.325 
#> 3     3 0.163 0.231  0.953 0.140  1.49 0.389 
#> 4     4 0.323 0.490  0.265 0.333  1.41 0.0960