For what I'm working on in R, I need to cut a numeric vector with a range of -1 to 1.3 into intervals of length 0.1. For this I want the intervals to be closed to the left, and open to the right. However, for some of the values equal to the break points, R puts them in the wrong interval. I would like to ask if other people have this problem too. You should easily be able to replicate my problem with the following code:
breaks = seq(-1, 1.3, by=0.1)
cut(0.3, breaks, right=FALSE)
In the above code, since the left intervals are closed and if I'm not mistaken, the value 0.3 should be put into the interval [0.3, 0.4). However, R puts it into the interval [0.2, 0.3). The same is true for other values between 0 and 1 that are equal to the break points. Curiously though, 0 is placed in the correct interval [0, 0.1), as is 1 which is put into [1, 1.1). 1.1 is also placed into the correct interval [1.1, 1.2), but 1.2 is subsequently placed into the same interval when it shouldn't.
Can anybody help me, and tell me whether they can replicate this problem or give any indication as to what I might be doing wrong?
Thanks!