[R] a < b < c is alway TRUE
macq at llnl.gov
Fri Jul 6 22:50:49 CEST 2001
Well now, look.
If I write down
3 + 2 * 7
we HAVE to have some agreement on how to do evaluate that, because
different ways give different results. Same thing with
3 < 2 < 1
We have to have rules that govern how it is interpreted.
We have rules. They are simple and easily understood. Others have
already reminded us what they are.
With the small, simple, addition of rules for converting between
numeric and logical types, the rules that govern 3 < 2 < 1 are the
same as those that govern an expression like
which is also ambiguous without an agreement on what the rules are.
The type conversion rule is nothing new--many other programming
languages also interpret 0 as false and 1 as true in various
contexts. For example, try this fortran program:
if (1) write(*,*) 'true'
if (0) write(*,*) 'false'
This type conversion rule is not a bad thing. It's just a rule. All
rules have pros and cons. Different languages make different choices.
We might think that 3 < 2 < 1 is an expression that makes sense, in
human terms, (perhaps because it kind of connects with the concept of
transitivity), and therefore R ought to interpret it that way. But
3 < 2 > 5
Huh? It's kind of nonsense. Unless you have well defined rules of syntax.
If you write expressions in language A but think they're going to get
interpreted according to the rules of language B, you're going to get
in trouble. The individual who posted the original question, when he
realized his mistake, said, in effect -- Oh, of course, I just had a
momentary lapse. (I think that's a fair characterization, apologies
if it's not.) He didn't start complaining about what he thought the
rules ought to be. In the present case the rules just aren't that
weird. In my opinion they are simple and reasonable.
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
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