Skip to content

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)

Arguments

cols

<tidy-select> Columns to transform. You can't select grouping columns because they are already automatically handled by the verb (i.e. summarise() or mutate()).

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.815  0.435  0.970 0.836   3.06 0.230
#> 2     2 0.0710 0.552  0.179 0.605   1.41 0.267
#> 3     3 0.527  0.204  0.778 0.907   2.42 0.310
#> 4     4 0.763  0.0310 0.886 0.0359  1.72 0.459