lundi 4 mars 2019

if else statement concatenation - R

This is a very common question: 1, 2, 3, 4, 5, and still I cannot find even an answer to my problem.

If a == 1, then do X.
If a == 0, then do Y.
If a == 0 and b == 1, then do Z.

Just to explain: the if else statements has to do Y if a==0 no matter the value of b. But if b == 1 and a == 0, Z will do additional changes to those already done by Y.

My current code and its error:

if (a == 1){
X
} else if(a == 0){
Y
} else if (a == 0 & b == 1){ 
Z}

Error in !criterion : invalid argument type

Aucun commentaire:

Enregistrer un commentaire