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.721 0.0620 0.478 0.927   2.19 0.372
#> 2     2 0.399 0.212  0.650 0.271   1.53 0.194
#> 3     3 0.701 0.966  0.425 0.820   2.91 0.229
#> 4     4 0.739 0.730  0.322 0.0115  1.80 0.351