I have three expressions, each involving multiplication with a logical or its negation. These logicals and their negation represent indicator variables, so that the expressions are conditionally evaluated:
-2*3*!T + 5*7*T
5*7*T + -2*3*!T
(-2*3*!T) + 5*7*T
I expect the above to produce the same result. However:
> -2*3*!T + 5*7*T
[1] 0 # unexpected!
> 5*7*T + -2*3*!T
[1] 35
> (-2*3*!T) + 5*7*T
[1] 35
I am sure this has something to do with operator precedence and type coercion, but I can't work out how it makes sense to even evaluate !T
after the *
.