0

I have 11 columns each representing a different race. Participants could select "Yes" or "No" for each column. I can't figure out how to merge all of these columns into one race variable where the "Yes" and "No" responses are converted to the specific race and if a participant selects more than one race, then have that be coded as "More than one race."

Any input would be appreciated!

Example Data

nel
  • 1
  • 1
    Welcome to SO. Please read and apply to your qestion: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Wimpel Mar 26 '21 at 16:04

1 Answers1

0
library(tidyverse)

df <- data.frame(q105_1 = c('', '', 'White', ''), 
                 q105_2 = c('Black', '', 'Black', ''))


twoOrMoreRaces <- df %>% 
  mutate(twoOrMoreMinority = case_when(
    q105_1 == 'White' & q105_2 == 'Black'~ 'Two or More races',
    TRUE ~ 'Single Race Reported'
  ))
Susan Switzer
  • 1,531
  • 8
  • 34