I have the following data:
tibble(car1 = c("honda", NA, NA),
car2 = c(NA, "mazda", NA),
car3 = c("toyota", "ferrari", "porsche")
) %>%
mutate(pick = coalesce(car1, car2, car3))
How can I capture the result of the selected column from coalesce into a new column (col_choice)?
Ideally I want the data to look as follows:
car1 car2 car3 pick col_choice
1 honda NA toyota honda car1
2 NA mazda ferrari mazda car2
3 NA NA porsche porsche car3