I have two columns for Race, Race 1 and Race 2. Race 2 has some corrections for Race 1, but it is most NA values.
Here is an example:
Race1 Race2
White American Indian
White American Indian
White Black
Black NA
Black NA
White NA
White NA
The results I want are as folloiws:
Race
American Indian
American Indian
Black
Black
Black
White
White
You can do the following:
library(dplyr)
df %>%
summarise(Race = coalesce(!!!select(rev(.), everything())))
Race
1 American_Indian
2 American_Indian
3 Black
4 Black
5 Black
6 White
7 White
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With