A dataset that I am using has recorded respondents' ethnicity. Responses are recorded across multiple variables, and respondents were allowed to pick more than one. Example:
ethnicity1 ethnicity2 ethnicity3 ethnicity4 ethnicity5 ethnicity6
1 0 0 0 0 0
0 2 0 0 0 0
0 0 3 4 0 0
Each ethnicity has its own column. I have recoded each column using the recode command so that different numbers represent different ethnicities (i.e., black would be 1, white would be 2, etc.) to try and make a single ethnicity variable
A) create a single column from the multiple columns combined
B) have it so that anyone who reported multiple columns gets designated "multiple".
My expected output would look like this:
Ethnicity
1
2
999
(I'm not sure whether it's best to have a numerical value signify multiple races for coding purposes, or have it be a character value as in "multiple')
Initially, I thought to do this but it's not going as I'd hope.
Ethnicity <- df %>% dplyr::na_if(0)
## create column for ethnicity
Ethnicity %>% unite("RaceEthnicity", ethnicity1:ethnicity5, na.rm = TRUE, remove = FALSE)