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, Joel F. Kincaid, Ph. D. Assistant Professor Department of Economics and Finance Franklin P. Perdue School of Business Salisbury University Salisbury Maryland, 21801 Phone: (410) 548-4416 Email: jfkincaid at salisbury.edu
white.denis@epamail.epa.gov
2003-Mar-27 21:32 UTC
[R] Logical Indexing of vectors -- Odd Behavior or....
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, >
Joel Kincaid wrote:> > 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, > > Joel F. Kincaid, Ph. D. > Assistant Professor > Department of Economics and Finance > Franklin P. Perdue School of Business > Salisbury University > Salisbury Maryland, 21801 > Phone: (410) 548-4416 > Email: jfkincaid at salisbury.edu > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-helpa) It has nothing to do with indexing. b) It not completely unexpected. In seq() some computations are involved, hence it''s just a very small inaccuracy which is expected when working with limited machines such as computers: options(digits=22) # some more details ... seq(.1, .9, .1) # Ah, that''s it! ;-) Uwe Ligges
Spencer Graves
2003-Mar-27 21:51 UTC
[R] Logical Indexing of vectors -- Odd Behavior or....
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
Joel Kincaid
2003-Mar-28 17:17 UTC
[R] Re: Logical Indexing of vectors -- Odd Behavior or....
Joel F. Kincaid, Ph. D. Assistant Professor Department of Economics and Finance Franklin P. Perdue School of Business Salisbury University Salisbury Maryland, 21801 Phone: (410) 548-4416 Email: jfkincaid at salisbury.edu>>> Joel Kincaid 03/27/03 16:17 PM >>>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)<snip snip >naive presumptions deleted. And so P <- round(seq(.1,.9,.1),2) produces the naively expected results. Thanks for your help. cheers,