I'm having difficulties in using %in% when dealing with floating point issue, e.g.
> x = seq(0.05, 0.3, 0.01)
> x %in% seq(0.15, 0.3, 0.01)
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE
[25] FALSE TRUE
I know it is because how computer stores floating points, but is there a function like dplyr::near
which could be used to replace %in%
? dplyr::near(x, y)
won't work if length of x
is different from y
.
Many thanks!