case_when in mutate pipe

As of version 0.7.0 of dplyrcase_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

Leave a Comment