[R] Intervals in function cut

JulioSergio juliosergio at gmail.com
Tue Nov 8 01:48:47 CET 2011


When I was studying the function cut I found this example:

> x <- rep(0:8, tx0)
> x
 [1] 0 0 0 0 0 0 0 0 0 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 4 4 4 5 5 5 5 5 5 
5 5 5 5 6
[39] 6 6 6 6 7 7 7 8 8 8 8 8

> cut(x, b = 8)
 [1] (-0.008,0.994] (-0.008,0.994] (-0.008,0.994] (-0.008,0.994] 
(-0.008,0.994]
 [6] (-0.008,0.994] (-0.008,0.994] (-0.008,0.994] (-0.008,0.994] (0.994,2]     
[11] (0.994,2]      (0.994,2]      (0.994,2]      (2,3]          (2,3]         
[16] (2,3]          (2,3]          (2,3]          (2,3]          (3,4]         
[21] (3,4]          (3,4]          (3,4]          (3,4]          (4,5]         
[26] (4,5]          (4,5]          (4,5]          (4,5]          (4,5]         
[31] (4,5]          (4,5]          (4,5]          (4,5]          (4,5]         
[36] (4,5]          (4,5]          (5,6]          (5,6]          (5,6]         
[41] (5,6]          (5,6]          (6,7.01]       (6,7.01]       (6,7.01]      
[46] (7.01,8.01]    (7.01,8.01]    (7.01,8.01]    (7.01,8.01]    (7.01,8.01]   
8 Levels: (-0.008,0.994] (0.994,2] (2,3] (3,4] (4,5] (5,6] ... (7.01,8.01]

I undestand that the resulting factor yields as its first component the 
corresponding "intervals" that the original vector (x) elements belong to. 
So, clearly, the first element of x, 0, belongs to (-0.008,0.994] because 
-0.008 < 0 <= 0.994. However, when I come to the 14th element of x, 
that is, 2, I don't see that it belongs to (2,3], because 2 < 2 <= 3, 
is strictly false according to the standard inverval notation 
(http://en.wikipedia.org/wiki/Interval_notation). Maybe, there is something 
I have not understood of either the cut function or the interval notation. 
Do you have 
any comments?

Thanks,

Sergio.



More information about the R-help mailing list