Reputation: 149
I'm trying to use dplyr case_when and pass variable but the result was not as expected.
Example:
library(dplyr)
mtcars %>%
mutate(cg = case_when(carb <= 2 ~ "low",
carb > 2 ~ "high")) ---this works
However, when I try to pass a variable, it returns all as "low"
var <- quo(carb)
mtcars %>%
mutate(cg = case_when(!!var <= 2 ~ "low",
!!var > 2 ~ "high"))
Upvotes: 1
Views: 1381