I have come across an odd thing I can't explain:
I am trying to find indices of elements from one vector in another vector, and I can do this with which()
or match()
:
test = seq(.1, 10, .1)
match(c(0.1, 0.2, 4, 7), test)
[1] 1 2 40 70
which(test %in% c(0.1, 0.2, 4, 7))
[1] 1 2 40 70
This makes sense, but if I reverse the sequence:
test = seq(10, .1, -.1)
match(c(0.1, 0.2, 4, 7), test)
[1] 100 NA 61 31
which(test %in% c(0.1, 0.2, 4, 7))
[1] 31 61 100
it cannot find 0.2
. My initial guess was that the format is not right, but it also cannot find 0.200
or test[99]
Can someone explain what is happening here?