I encountered the following inconsistent behaviour of cut
which gives me a headache:
x <- 0.2316
cut(x, c(0, 0.2315, 10)) #gives 0.232 as cutpoint and choses second interval
## [1] (0.232,10]
## Levels: (0,0.232] (0.232,10]
cut(x, c(0, 0.232, 10)) #choses first interval when taking the same cutpoint it just gave (0.232)
## [1] (0,0.232]
## Levels: (0,0.232] (0.232,10]
The problem is that cut
seems to chose the interval before formatting (rounding) the cut points. This leads to the inconsistent behaviour in the example that it chooses the second interval but would have chosen the first interval according to the given cut point (which can be seen in the last line).
This is a problem for me because I have two functions in my package: One is calculating the cut points and the second is determining the right intervals where to put new data points. In the example above the same data point is put into the second interval in the first function but into the first interval in the second function - displaying the exact same cut points! That can lead to some strange behaviour in my package!
My question
Is this a known issue? And if yes are there any workarounds? Thank you
Edit
I know that you can change the number of decimal places with dig.lab
yet the same problem would occur if you had cut points with more decimal places. The above example is just a demonstration of a more general problem!