I would like to use case_when within mutate_at, as in the following example:
mtcars %>%
mutate_at(.vars = vars(vs, am),
.funs = funs(case_when(
. %in% c(1,0,9) ~ TRUE
. %in% c(2,20,200) ~ FALSE
TRUE ~ as.character(.)
)))
alternative version using . = in funs() call also does not work.
mtcars %>%
mutate_at(.vars = vars(vs, am),
.funs = funs(. = case_when(
. %in% c(1, 0, 9) ~ TRUE
. %in% c(2, 20, 200) ~ FALSE
TRUE ~ as.character(.)
)))
Desired results
mtcars %>%
mutate_at(.vars = vars(vs, am),
.funs = funs(ifelse(. %in% c(1, 0, 9), TRUE, FALSE)))
FALSE could be replaced with second ifelse() call, which I didn't include for brevity.