[R] a < b < c is alway TRUE

Duncan Murdoch murdoch at stats.uwo.ca
Fri Jul 6 15:35:14 CEST 2001


On Fri, 6 Jul 2001 13:21:51 +0200, you wrote in message
<3B45BB6F.6582.E1B7B at localhost>:

>what's surprising is the following:
>> FALSE<1
>[1] TRUE
>> FALSE>1
>[1] FALSE
>> TRUE<1
>[1] FALSE
>> TRUE>1
>[1] FALSE
>
>because of symmetry i'd expect TRUE>1 to be TRUE.

In R like C, FALSE is 0 and TRUE is 1.  This is a bad thing, but it's
too late to change it now.  With that substitution, all the results
look reasonable:  0>1, 1<1 and 1>1 are all false, but 0<1 is true.

Why a bad thing?  Because it leads to absurdities like this whole
thread has been discussing!

What should they have done?  They should have done what Fortran,
Pascal, etc. do, and have a separate logical or boolean type that
isn't automatically converted to a numerical type.  In Pascal for
instance, "3 < 2 < 1" is flagged as a syntax error, because you can't
compare a boolean to an integer.  If you really want to do the weird
comparison that R is doing, you need to enter it as "ord(3 < 2) < 1",
and any reader will see that you're doing something weird.

Duncan Murdoch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list