I came across some strange (or just not expected?) Behavior of the seq function. When creating a simple sequence, some values ββcannot be matched correctly with the == operator. See This Minimal Example:
my.seq <- seq(0, 0.4, len = 5) table(my.seq) # ok! returns 0 0.1 0.2 0.3 0.4 # 1 1 1 1 1 which(my.seq == 0.2) # ok! returns 3 which(my.seq == 0.3) # !!! returns integer(0)
When creating my sequence manually, it seems to work:
my.seq2 <- c(0.00, 0.10, 0.20, 0.30, 0.40) which(my.seq2 == 0.3)
Do you have any explanation? I solved the problem using which(round(my.seq, 2) == 0.3) , but I would be wondering what the problem is.
Thanks in advance for your comments.
source share