Open jack-davison opened 1 month ago
Note that if you want to
"summarise everything except this one thing, which I'd like to group by"
then you can use everything()
in the .cols
argument of across()
:
dat <-
tibble::tibble(x = 1:5,
y = 1:5,
z = c(1, 1, 1, 2, 2))
dplyr::summarise(dat, across(everything(), sum), .by = z)
#> # A tibble: 2 × 3
#> z x y
#> <dbl> <int> <int>
#> 1 1 6 6
#> 2 2 9 9
Indeed, the docs say that:
.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()).
Interesting interaction in
summarise(across(...))
- if I try to deselect some grouping var,z
, inacross()
and but summarise by it using.by =
, it errors claiming that it doesn't exist.Note this occurs regardless of the type of
z
- numeric, character, etc.I'd expect this isn't a totally rogue thing to do - "summarise everything except this one thing, which I'd like to group by"
Created on 2024-09-18 with reprex v2.1.1