You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a table is grouped by a column x, I can still alter the column with mutate using mutate(x = 2*x). However, if I try to do the same thing using across, I get an error saying that "Column x doesn't exist".
Is the fact that across cannot access grouping columns intentional?
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, uniondf<- tibble(x= rep(1:2, 2:3)) %>% group_by(x)
df %>%
mutate(x=x*2)
#> # A tibble: 5 × 1#> # Groups: x [2]#> x#> <dbl>#> 1 2#> 2 2#> 3 4#> 4 4#> 5 4df %>%
mutate(across(x, ~.*2))
#> Error: Problem with `mutate()` input `..1`.#> ℹ `..1 = across(x, ~. * 2)`.#> x Can't subset columns that don't exist.#> x Column `x` doesn't exist.#> ℹ The error occurred in group 1: x = 1.
If a table is grouped by a column
x
, I can still alter the column with mutate usingmutate(x = 2*x)
. However, if I try to do the same thing usingacross
, I get an error saying that "Columnx
doesn't exist".Is the fact that
across
cannot access grouping columns intentional?Created on 2021-07-30 by the reprex package (v2.0.0)
The text was updated successfully, but these errors were encountered: