From savicky at cs.cas.cz  Mon Mar 16 17:41:54 2009
From: savicky at cs.cas.cz (Petr Savicky)
Date: Mon, 16 Mar 2009 17:41:54 +0100
Subject: [Rd] Match .3 in a sequence
In-Reply-To: <48f8cced0903160636k112500f6k4b8d46c1ac775d89@mail.gmail.com>
References: <48f8cced0903160636k112500f6k4b8d46c1ac775d89@mail.gmail.com>
Message-ID: <20090316164154.GB15686@cs.cas.cz>

On Mon, Mar 16, 2009 at 06:36:53AM -0700, Daniel Murphy wrote:
> Hello:I am trying to match the value 0.3 in the sequence seq(.2,.3). I get
> > 0.3 %in% seq(from=.2,to=.3)
> [1] FALSE

As others already pointed out, you should use seq(from=0.2,to=0.3,by=0.1)
to get 0.3 in the sequence. In order to get correct %in%, it is also
possible to use round(), for example
  > 0.3 %in% round(seq(from=0.2,to=0.3,by=0.1),digits=1)
  [1] TRUE

See FAQ 7.31
  http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
or 
  http://wiki.r-project.org/rwiki/doku.php?id=misc:r_accuracy:decimal_numbers
for more detail.

Petr.



[Rd] Match .3 in a sequence
Petr Savicky