Hi,
During the course of putting together a function I came across some
unexpected behaviour when using seq() and %in%.

I am creating two numeric vectors using seq(), and then using %in% to find
the values in one vector that are in the other. Sometimes all the values
are found, but sometimes a value is not found. It seems that the behaviour
is inconsistent and I don't understand why.

Below are some reproducible examples:

vec1 <- seq(from = 0.1, to = 20, by = 0.1)
vec2 <- seq(from = 2, to = 20, by = 2)
vec1[vec1 %in% vec2]
[1]  2  4  6  8 10 12 14 16 20

The value 18 is not found.

Starting vec1 at 0.2:

vec1 <- seq(from = 0.2, to = 20, by = 0.1)
vec2 <- seq(from = 2, to = 20, by = 2)
vec1[vec1 %in% vec2]
[1]  2  4  8 10 12 14 16 18 20

Now the value 6 is not found.

Starting vec1 at 0.5:

vec1 <- seq(from = 0.5, to = 20, by = 0.1)
vec2 <- seq(from = 2, to = 20, by = 2)
vec1[vec1 %in% vec2]
[1]  2  4  6  8 10 12 14 16 18 20

Now all the values are found.

Can someone please explain what is happening? Why should the starting value
of vec1 make a difference?

Thanks

Finlay

R version info:

platform       x86_64-pc-linux-gnu
arch           x86_64
os             linux-gnu
system         x86_64, linux-gnu
version.string R version 3.0.1 (2013-05-16)

	[[alternative HTML version deleted]]

