mardi 1 décembre 2020

case_when or ifelse for building a new varaible

I want to build a new variable base on some condition. My codes look like:

df%>% mutate (PassFL= case_when(ID %in% PassID$ID~"Y",
                                ID !%in% PassID$ID~"N")

It won't run. I think !%in% is incorrect. How should I correct it.

Also, I have some difficulty follow ifelse. Often forget ) or lost track. Could anyone give some tips on how to follow ifelse? Is any disadvatage of using case_when?

Aucun commentaire:

Enregistrer un commentaire