I want to transform a set of variables differently depending on a condition. I found a solution here
Example: I want to substract 4 from all variables 'mpg' to 'disp' if 'gear' equals 4, otherwise I substract 3.
mtcars %>%
mutate_at(vars(mpg:disp),
funs(case_when(gear == 4 ~ . - 4L, TRUE ~ . -3L)))
But I get this warning:
funs() is soft deprecated as of dplyr 0.8.0
Please use a list of either functions or lambdas:
# Simple named list:
`list(mean = mean, median = median)`
# Auto named with `tibble::lst()`:
`tibble::lst(mean, median)`
# Using lambdas
`list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))`
This warning is displayed once per session.
Is there a better solution to my problem that avoids using funs()
?
repro do so
mtcars %>% mutate_at(vars(mpg:disp), ~ case_when(gear == 4 ~ . - 4L, TRUE ~ . -3L))