Reputation: 555
I have a dataframe
structure(list(Race = structure(c(3L, 2L, 3L, 9L, 9L, 11L,
5L, 11L, 3L, 3L, 3L, 3L, 7L, 3L, 11L, 5L, 9L, 10L, 9L, 10L, 2L,
3L, 2L, 6L, 9L, 10L, 3L, 10L, 8L, 3L, 5L, 1L, 2L, 9L, 4L, 3L), .Label = c("Black or African American",
"Black or African American,White or Caucasian", "East Asian",
"East Asian,Pacific Islander", "Hispanic or Latino/a", "Other",
"Pacific Islander", "South Asian", "White or Caucasian", "White or Caucasian,Hispanic or Latino/a",
"White or Caucasian,Middle Eastern"), class = "factor")), class = "data.frame", row.names = c(NA,
-36L))
I'm comparing multiple races on census data. What I'd like to do is create a new variable saying if the person is a minority or not based on if that row contains anything other than ONLY "White or Caucasian". So if someone lists themselves as "Pacific Islander" they will be listed as "Minority" in the new variable. If they are listed as only "White or Caucasian" they will be "Majority". Notice that some of these cells have a combination of races including "White or Caucasian" plus some other race. Anyone with more than one race should still be considered "Minority"
Upvotes: 0
Views: 74
Reputation: 349
Why not simply:
df %>% mutate(new_var = ifelse(Race=="White or Caucasian","Majority","Minority"))
Upvotes: 2