vendredi 5 février 2021

How to run ifelse in R for multiple values from a list and to set condition boundary between those in list vs those in not? [duplicate]

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

Aucun commentaire:

Enregistrer un commentaire