Hi
Would someone help me understand why across and c_across are positioned differently in functions. This knowledge will help me easily remember their positions so that I shouldn't be making mistakes in using the functions.
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
df <- tibble(id = 1:6, w = 10:15, x = 20:25, y = 30:35, z = 40:45)
df %>%
rowwise() %>%
mutate(total = sum(c_across(w:z))) %>%
ungroup() %>%
mutate(across(w:z, ~ . / total))
#> # A tibble: 6 x 6
#> id w x y z total
#> <int> <dbl> <dbl> <dbl> <dbl> <int>
#> 1 1 0.1 0.2 0.3 0.4 100
#> 2 2 0.106 0.202 0.298 0.394 104
#> 3 3 0.111 0.204 0.296 0.389 108
#> 4 4 0.116 0.205 0.295 0.384 112
#> 5 5 0.121 0.207 0.293 0.379 116
#> 6 6 0.125 0.208 0.292 0.375 120
#why isn't the syntax for for c_across(w:x, sum)
#Be free to use any other example dataset that you are comfortable with
#Thanks
Created on 2021-02-09 by the reprex package (v0.3.0)