I have a script that creates a column so that I know which rule should be applied to each row in a dataframe.
EndoSubset$FU_Group<-ifelse(EndoSubset$IMorNoIM=="No_IM","Rule1",
ifelse(EndoSubset$IMorNoIM=="IM","Rule2",
ifelse(EndoSubset$IMorNoIM=="AnotherIM","Rule3",
"NoRules")))
I want to make this into a function so that there can be any number of rules and any number of conditions for a column so it could be:
EndoSubset$FU_Group<-ifelse(EndoSubset$IMorNoIM=="No_IM","Rule1",
ifelse(EndoSubset$IMorNoIM=="IM","Rule2",
ifelse(EndoSubset$IMorNoIM=="AnotherIM","Rule3",
ifelse(EndoSubset$IMorNoIM=="SomeOtherIM","Rule4",
ifelse(EndoSubset$IMorNoIM=="LotsOfIM","Rule5",
"NoRules")))
I understand that I can use the ellipsis for this but I don't understand how to use this for both the conditional string ("No_IM, "IM,"AnotherIM", etc) and the Rule string at the same time ("Rule1","Rule2","Rule3" etc.)