Yes, the round(seq( )) sollution does it. Many thanks to the sender of this (and other similar) solutions.
TB On Thu, Aug 16, 2012 at 3:45 AM, Petr Savicky <savi...@cs.cas.cz> wrote: > On Wed, Aug 15, 2012 at 10:37:17PM +1000, Tom Bird wrote: > > Hi, > > > > I am using 32-bit R v 2.15.1, on Mac OsX v 10.6.8 with R GUI 1.52 Leopard > > build 32-bit (6188). I have also replicated this error on R 2.13.2 on a > > windows 7 machine. > > > > In some sequences of numbers, I am unable to use the which() function to > > index certain values. It seems to be primarily numbers with a 3 in the > > decimal. > > For example: > > > > > S=seq(0,4,0.01) > > > > > which(S==2.02) > > > > [1] 203 > > > > > which(S==2.03) > > > > integer(0) > > > > > which(S==2.04) > > > > [1] 205 > > > > > which(S==2.04) > > > > [1] 205 > > > > > which(S==3.03) > > > > integer(0) > > > > > which(S==3.3) > > > > integer(0) > > > > > which(S==3.) > > > > [1] 301 > > > > > which(S==3.5) > > > > [1] 351 > > Hi. > > This is a rounding problem. > > print(S[204], digits=20) > [1] 2.0300000000000002487 > > print(2.03, digits=20) > [1] 2.0299999999999998046 > > Use function round(, digits), for example > > S <- round(seq(0,4,0.01), digits=7) > > which(S==2.03) > > [1] 204 > > which(S==3.03) > > [1] 304 > > Hope this helps. > > Petr Savicky. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.