Another R inferno: if () {} else {} + x
if (TRUE) {
0
} else {
2
} + 3
will return 0 and not 3 because the priority order is:
if (TRUE) then {0}
else
{2} + 3
This is clearly counter-intuitive.
As a general rule, I propose to never use result of a if statement directly in a computing.
Note that ifelse() gives more normal result:
ifelse(TRUE, 0, 2) + 3
will return 3
Commentaires
Enregistrer un commentaire