[R] strange issue with "which" on "seq"

From: <james.foadi_at_diamond.ac.uk>
Date: Wed, 09 Jun 2010 12:16:40 +0100


Dear R community,
I am puzzled by the following lines:

> v <- seq(-0.5,0.5,by=0.1)
> v

  [1] -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5
> which(v == -0.4)

  [1] 2
> which(v == 0)

  [1] 6
> which(v == 0.1)

integer(0)

> which(v == 0.2)
integer(0)
> which(v == 0.3)
integer(0)

> which(v == 0.4)

  [1] 10
> which(v == 0.5)
  [1] 11

Why "which" can only match some of the values in "v"? Are the numbers generated by "seq" not exact fractional numbers? Please, help me to understand this.

J

Dr James Foadi PhD
Membrane Protein Laboratory (MPL)
Diamond Light Source Ltd
Diamond House
Harewell Science and Innovation Campus
Chilton, Didcot
Oxfordshire OX11 0DE

Email : james.foadi_at_diamond.ac.uk
Alt Email: j.foadi_at_imperial.ac.uk

-- 
This e-mail and any attachments may contain confidential...{{dropped:8}}

______________________________________________
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 Wed 09 Jun 2010 - 11:34:37 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 Wed 09 Jun 2010 - 12:00:29 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