I have multiple columns in R studio that correspond to race/ethnicity. These race/ethnicity variables are specified in 6 different columns. Participants are allowed to check multiple columns if it applies to them.
Race.ethnicity1 = american indian or alaska native, race.ethnicity2 = asian or asian american, race.ethnicity3 = black or african-american, race.ethnicity4= native american or pacific islander, race.ethnicity5 = white, race.ethnicity6 = other)
I am trying to combine these 6 different columns into one Race/Ethnicity column in R. So, if participants clicked multiple selections, they would be coded as biracial/multiracial If they clicked white and no other race/ethnicty selection, then they will be coded as white if they click black and no other selection, then they are coded as black, and vice versa
I began the code with
df$RaceEthnicity <- ifelse(df$Race.Ethnicity_5 == "White" & !(PT_baseline$Race.Ethnicity_1 == "NA" | PT_baseline$Race.Ethnicity_2 == "NA" | PT_baseline$Race.Ethnicity_3 == "NA" | PT_baseline$Race.Ethnicity_4 == "NA" | PT_baseline$Race.Ethnicity_6 == "NA"), "White", NA) table(PT_baseline$RaceEthnicity)
But, I think this method of doing things would be very long. Is there a simpler way of doing this code?