mardi 12 février 2019

mutate with multiple conditions using if_else or ifelse

I'm trying to create a new variable "lab_conf" based on meeting either condition for 2 other variables "diagnosis" and "PC_R". This is the code I'm using:

mutate(lab_conf = ifelse( (diagnosis == "confirmed")|(PC_R == "pos"), "pos", "neg"))

The output I'm getting is showing NA where it should show "neg", so I'm only getting 2 values; "pos" or "NA". I'd like the values for this new variable to be either "pos", "neg", or NA based based on the conditions specified, where NA would be if its NA in both conditions.

Aucun commentaire:

Enregistrer un commentaire