[Rd] a couple of things about ":"
Liaw, Andy
andy_liaw at merck.com
Thu Apr 7 21:39:44 CEST 2005
Dear R-devel,
A colleague was recently surprised by the behavior of the ":" operator (as
sequence generator), so I decided to dig a little bit. Here are a couple of
things I found.
- ?":" seems a bit imprecise. The Details section says:
`The operator : and the seq(from, to) form generate the sequence from,
from+1, ..., to.'
but `to' is not necessarily included in the output; e.g.,
> 0.5:3
[1] 0.5 1.5 2.5
Then it says: `The second form generates from, from+by, ..., up to the
sequence value less than or equal to to.' That's not necessarily true,
either, if `by' is negative:
> 0.5:-3
[1] 0.5 -0.5 -1.5 -2.5
- It seems counter-intuitive to allow non-integer values as operand for ":".
It also seems a bit odd that 1:2 returns something with storage.mode
integer, whereas 0.5:2 gives doubles. Would it make sense to disallow
non-integer operands to ":"? I can't think of a situation when non-integer
operands for ":" would be good...
Best,
Andy
More information about the R-devel
mailing list