0

I have a numeric vector as

[1] 33.6 23.3 43.1 30.5 38.0 27.1 30.1 25.8 39.8 36.6 39.4 22.2 31.6 33.2 34.0 40.2 45.4 27.4 42.0 29.7 33.7 34.7 37.7 40.5 32.9 25.4
 [27] 28.9 28.6 48.8 37.1 23.8 24.7 33.9 39.0 26.1 29.5 33.3 31.2 53.2 34.5 32.8 37.4 34.3 40.6 47.9 50.0 40.9 32.5 35.4 32.7 45.0 27.6
 [53] 35.9 30.4 52.3 30.9 40.1 37.5 35.5 42.8 34.2 42.6 41.8 34.6 28.8 37.2 36.7 44.0 46.2 43.6 44.1 30.8 25.6 38.2 30.0 25.9 32.4 36.3
 [79] 27.5 37.9 26.0 38.7 21.9 28.0 32.3 21.0 25.5 24.8 26.6 23.5 26.8 35.1 43.3 39.9 28.7 36.5 29.8 38.5 34.9 38.4 39.2 48.3 32.0 45.7
[105] 24.2 35.0 42.4 26.2 35.7 42.9 37.0 34.1 29.9 59.4 26.7 37.6 46.1 41.3 27.3 44.2 42.3 40.7 46.5 25.1 29.3 22.1 30.3 28.5 31.3 27.0
[131] 42.1 36.8 35.2 28.4 40.0 41.5 36.1 40.8 23.4 37.8 28.3 27.7 49.6  0.0 24.1 26.4 33.8 22.9 44.5 49.3 36.4 24.3

I am using R cut function to convert this into categorical and I am using the following breakpoints

-0.010000,9.893333,19.796667,29.700000,39.603333,49.506667,59.410000

my r-command is as follows

cut(x,breaks,include.lowest = FALSE,right=TRUE)

but this command groups the observation 29.7 into the category (29.7,39.6] whereas it should be in the category (19.8,29.7].

Can anyone please inform what went wrong?

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
  • 2
    This might be a reason - http://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal – zx8754 May 16 '16 at 09:55
  • when I use options(digits=18) I get the break point 29.7 as 29.6999999999999957 so it is actually not 29.7 may be some floating point issue in R – Sushovan Chakraborty May 16 '16 at 10:32

0 Answers0