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 x 7 #> # Rowwise: #> id w x y z sum sd #> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 1 0.0349 0.315 0.516 0.000104 0.865 0.244 #> 2 2 0.439 0.856 0.869 0.205 2.37 0.326 #> 3 3 0.644 0.540 0.857 0.945 2.99 0.187 #> 4 4 0.995 0.873 0.346 0.281 2.50 0.363