Re: [R] problem with "which"

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Thu, 24 Apr 2008 04:02:02 +0000 (UTC)

Melanie Abecassis <Melanie.Abecassis_at_noaa.gov> wrote in news:481002B0.3080704_at_noaa.gov:

> Hi,
> I'm having trouble with the "which" or the "seq" function, I'm not
> sure. Here's an example :
>
>
> > lat=seq(1,2,by=0.1)
> > lat
> [1] 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0
>
> > which(lat==1)
> [1] 1
> > which(lat==1.1)
snip
> [1] 7
> > which(lat==1.7)
> *integer(0)*
> This doesn't seem to happen with integers.
> Am I missing something ?? Is there a better function for
> non-integers ?

Read the FAQ
(Section 7.31 Why doesn't R think these numbers are equal? http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

and look at this:
> lat - 1.7

 [1] -7.000000e-01 -6.000000e-01 -5.000000e-01 -4.000000e-01
 [5] -3.000000e-01 -2.000000e-01 -1.000000e-01  2.220446e-16
 [9]  1.000000e-01  2.000000e-01  3.000000e-01

-- 
David Winsemius

______________________________________________
R-help_at_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.
Received on Thu 24 Apr 2008 - 04:05:13 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Apr 2008 - 06:30:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive