samedi 24 mars 2018

creating a new variable that combines several others using if else

I am using a large data.frame of health conditions and outcomes, I wish to combine 10 health conditions into a single condition, If the patient has either a, or b, c, or d, etc. then the condition would be condition one. I am trying to code it like this:

      dataset$one <-  ifelse(dataset, (dataset$a == 1)|
                            (dataset$b == 1)|
                            (dataset$c  == 1)|
                            (dataset$d  == 1),  1, 0)

This seems to work for the first condition, but not when I add conditions. Perhaps R does not allow multiple or statements? Any suggestions?

Aucun commentaire:

Enregistrer un commentaire