How would I call a function like mutate_at for two columns at the same time?
If for example I had a df with consistent columns names and I want to find the difference I could do something like:
library(dplyr)
df <-
tibble(x_1 = 1:5,
x_2 = 1:5,
y_1 = 6:10,
y_2 = 6:10)
df %>%
mutate(x_dif = x_1 - x_2,
y_dif = y_1 - y_2)
It is easy to do this manually, but I'd like to apply a function to both columns in a scalable fashion. I'm conceptually thinking of this as two mutate_at's where I would do vars(x_1, y_1) and vars(x_2, y_2) at the same time in one call, but I don't think this is the right approach.