powered by
c_across() is designed to work with rowwise() to make it easy to perform row-wise aggregations. It has two differences from c():
c_across()
rowwise()
c()
It uses tidy select semantics so you can easily select multiple variables. See vignette("rowwise") for more details.
vignette("rowwise")
It uses vctrs::vec_c() in order to give safer outputs.
vctrs::vec_c()
c_across(cols = everything())
<tidy-select> Columns to transform. Because across() is used within functions like summarise() and mutate(), you can't select or compute upon grouping variables.
tidy-select
across()
summarise()
mutate()
across() for a function that returns a tibble.
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)) )
Run the code above in your browser using DataLab