I would like to add a new column in my dataset, based on two other columns.
I know I can achieve this task by hard-coding all combinations myself, for instance like this:
mtcars %>%
rowwise() %>%
mutate(Comb = case_when(vs == 0 & am == 0 ~ 0,
vs == 1 & am == 0 ~ 1,
vs == 0 & am == 1 ~ 2,
vs == 1 & am == 1 ~ 3))
Is there any tidyverse function I could use instead? With only 4 combinations I can hard-code it, but with more it becomes impossible.