Open beanumber opened 2 years ago
OK, I did that. It still doesn't work
library(tidyverse)
x <- c(3, 2, 1, 1, 4, 5, 6)
ds <- tibble(id = x) %>%
mutate(
x_grp =
case_when(
id %in% c(1, 2, 3) ~ "sustainable",
id == 4 ~ "experimental",
id == c(5, 6) ~ "fossil fuel"
)
)
#> Warning in id == c(5, 6): longer object length is not a multiple of shorter
#> object length
ds
#> # A tibble: 7 × 2
#> id x_grp
#> <dbl> <chr>
#> 1 3 sustainable
#> 2 2 sustainable
#> 3 1 sustainable
#> 4 1 sustainable
#> 5 4 experimental
#> 6 5 <NA>
#> 7 6 <NA>
Created on 2022-05-19 by the reprex package (v2.0.1)
Created on 2022-05-19 by the reprex package (v2.0.1)