I'm trying to use multiple functions across multiple variables, like this:
https://dplyr.tidyverse.org/dev/articles/colwise.html#multiple-functions
I can get this to work:
df <- tibble(a = 2, b = 4, c = 8)
div_x_by_n <- list(
div_2 = ~.x/2,
div_4 = ~.x/4)
df %>% mutate(across(everything(), div_x_by_n))
However, if I want to reference a column in the dataframe, I get an error:
div_x_by_ab <- list(
div_a = ~.x/a,
div_b = ~.x/b)
df %>% mutate(across(everything(), div_x_by_ab))
Error: Problem with mutate() input ..1.
x object 'a' not found
i Input ..1 is across(everything(), div_x_by_a).
How can I reference columns from my dataframe within the list of functions that's passed to across?