dimanche 13 mai 2018

New variable in R with IF statement

Say I have columns X1 and X2 and X3. Basically: I want to make a new variable Z that is equal to the first available value from X1-X3. If values are missing for all X1-X3 I want to set Z to NA. Thanks so much!

X1  X2  X3  Z 
1   2   3   1 
NA  5   6   5 
NA   NA  9  9 
NA   NA  3  3  
NA  NA  NA   

Aucun commentaire:

Enregistrer un commentaire