Q:

Understanding cut output

I am not able to understand the below behavior of cut. 
> data = seq(0,1,.2)
> data
[1] 0.0 0.2 0.4 0.6 0.8 1.0
> cuts = cut(data, c(0, 0.25, 0.5, .6, 0.9, Inf))
> summary(cuts)
  (0,0.25] (0.25,0.5]  (0.5,0.6]  (0.6,0.9]  (0.9,Inf]       NA's 
         1          1          0          2          1          1

As per my understanding the intervals made by cut are closed on right. Thus the interval (0.5,0.6] should have one element (.6) instead of zero. Similarly interval (0.6,0.9] should have 1 element only instead of 2.
Where am I wrong.

A:

It has to do with a slight error in the numbers that are generated by seq:
> data[4] - 0.6
[1] 1.110223e-16

From that, you can see that data[4] is ever so slightly larger than 0.6, hence it goes up to the next bucket.
The reason for this is because not all numbers can be represented exactly in any encoding scheme that doesn't have infinite storage. The best you can hope for is a close enough approximation. In this case, an error of 10-16 for a value of order 10-1 is minuscule, but non-zero.

