[R] Logical Indexing of vectors -- Odd Behavior or....

Spencer Graves spencer.graves at pdf.com
Thu Mar 27 22:51:04 CET 2003


I get the same answer from S-Plus 6.1 as R 1.6.2 (under Windows 2000)

tst.seq <- seq(.1, .9, by=.1)
(outer(tst.seq, round(tst.seq, 1), ">") %*% rep(1,9))[,1]
[1] 0 1 3 3 4 5 7 7 8

Enjoy,
Spencer Graves

white.denis at epamail.epa.gov wrote:
> Notice that
> 
> 
>>seq (.1, .9, by=.1)[3] - 0.3
> 
> [1] 5.551115e-17
> 
> See the thread "[R] round() seems inconsistent when rounding 5s" about
> March 16 on the same issue, inexact representation.
> 
> 
>>R-Community,
>>
>>I'm puzzled by the following behavior in R 1.6.2 and have found no
>>reference to this in the archives:
>>
>>
>>>P <- seq(.1,.9,by=.1)
>>
>>>P[P > .4]
>>
>>[1] 0.5 0.6 0.7 0.8 0.9
>>as expected. However,
>>
>>>P[P > .3]
>>
>>[1] 0.3 0.4 0.5 0.6 0.7 0.8 0.9
>>    ???
>>Which is unexpected. Furthermore on the logical side
>>
>>>P>.1
>>
>>[1] FALSE TRUE TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
>>
>>>P>.2
>>
>>[1] FALSE FALSE TRUE TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
>>
>>>P>.3
>>
>>[1] FALSE FALSE TRUE TRUE  TRUE  TRUE  TRUE  TRUE  TRUE
>>
>>>P>.4
>>
>>[1] FALSE FALSE FALSE FALSE TRUE TRUE  TRUE  TRUE  TRUE
>>
>>>P>.5
>>
>>[1] FALSE FALSE FALSE FALSE FALSE TRUE TRUE  TRUE  TRUE
>>
>>>P>.6
>>
>>[1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE
>>
>>>P>.7
>>
>>[1] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE  TRUE
>>
>>
>>What's with .3 and .7? Any pointers to where I might find out the info
>>would be greatly appreciated,
>>
>>I'm running 1.6.2 on windows XP,
>>Sincerely,
>>
> 
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help



More information about the R-help mailing list