It seems dplyr::case_when
doesn\'t behave as other commands in a dplyr::mutate
call. For instance:
library(dplyr)
case_when(mtcars
In addition to @akrun's answer above, be aware that the closing parenthesis for the case_when()
cannot be put it onto its own line.
For example, this works OK:
mtcars %>%
mutate(cg = case_when(
.$carb <= 2 ~ "low", .$carb > 2 ~ "high"))
but this does not:
mtcars %>%
mutate(cg = case_when(
.$carb <= 2 ~ "low", .$carb > 2 ~ "high")
)