vendredi 3 novembre 2017

Multiple 'OR' using ifelse in R

I would like to make the several 'OR' conditions like this:

 dta_EARTHQbb <- dta_EARTHQb %>%
      mutate(ASS = ifelse(CODE=="01"|CODE=="02"|CODE=="03", 1, 0))

If the CODE is 01, or 02, or 03, it attached '1' otherwise '0'.

I want to make another approach as the conditions are larger like this:

    CONDITONa = c(01,02,03)  
dta_EARTHQbb <- dta_EARTHQb %>%
          mutate(ASS = ifelse(CODE==CONDITIONa, 1, 0))

Howev..., it does not work.. How do I adjust this code..?

Aucun commentaire:

Enregistrer un commentaire