Cut by Defined Interval

To cut unto pre-defined intervals, you can specify a vector of breaks using the breaks parameter.

Define some data:

x <- sample(0:20, 100, replace=TRUE)
x

Now cut x at 0, 10 and 20:

cut(x, breaks=c(0, 10, 20), include.lowest=TRUE)

  [1] (10,20] [0,10]  [0,10]  (10,20] (10,20] (10,20] [0,10]  (10,20] (10,20]
 [10] (10,20] [0,10]  (10,20] (10,20] (10,20] [0,10]  (10,20] [0,10]  [0,10] 
 [19] [0,10]  (10,20] [0,10]  [0,10]  [0,10]  (10,20] [0,10]  (10,20] (10,20]
 [28] (10,20] (10,20] [0,10]  [0,10]  [0,10]  [0,10]  (10,20] [0,10]  [0,10] 
 [37] [0,10]  [0,10]  (10,20] (10,20] (10,20] (10,20] [0,10]  (10,20] [0,10] 
 [46] (10,20] [0,10]  (10,20] (10,20] [0,10]  [0,10]  (10,20] (10,20] (10,20]
 [55] [0,10]  [0,10]  (10,20] [0,10]  [0,10]  [0,10]  [0,10]  (10,20] (10,20]
 [64] (10,20] [0,10]  [0,10]  (10,20] (10,20] (10,20] (10,20] (10,20] (10,20]
 [73] (10,20] [0,10]  [0,10]  [0,10]  (10,20] [0,10]  (10,20] [0,10]  (10,20]
 [82] [0,10]  [0,10]  (10,20] [0,10]  [0,10]  [0,10]  (10,20] (10,20] [0,10] 
 [91] [0,10]  [0,10]  (10,20] (10,20] [0,10]  [0,10]  [0,10]  [0,10]  (10,20]
[100] (10,20]
Levels: [0,10] (10,20]

Leave a Comment