As of version 0.7.0
of dplyr
, case_when
works within mutate
as follows:
library(dplyr) # >= 0.7.0
mtcars %>%
mutate(cg = case_when(carb <= 2 ~ "low",
carb > 2 ~ "high"))
For more information: http://dplyr.tidyverse.org/reference/case_when.html