mercredi 8 décembre 2021

R: unexpected behaviour adding two if(){}else{} constructs

Consider the following R input:

if(TRUE){1}else{0} + if(TRUE){1}else{0}

The result is 1, but I was expecting 2. If I enclose each if-else statement in parentheses,

(if(TRUE){1}else{0}) + (if(TRUE){1}else{0})

then the result is 2.

Can someone explain this behaviour?

Aucun commentaire:

Enregistrer un commentaire