0

I have a script that looks like this

df$Col1<-ifelse(df$race == STOP_AUDIT[RACE],
                         "Yes", "No")

I have a list called RACE

RACE<-c("WHITE","BLACK","HISPANIC","ASIAN")

This is the outcome i want for my dataset.

           race|Col1
 BLACK          Yes
 ASIAN          Yes
 WHITE          Yes
 WHITE HISPANIC No
 HISPANIC       Yes
 ASIAN          Yes
 BLACK HISPANIC No
user35131
  • 1,105
  • 6
  • 18

1 Answers1

2

You can use %in% to check when an item is in another vector. This is vectorised, as in:

df$Col1<-ifelse(df$race %in% RACE, "Yes", "No")
Leonardo
  • 2,439
  • 33
  • 17
  • 31
Miff
  • 7,486
  • 20
  • 20