S3-method for cut applied to integer vectors where all outcome factors are integer intervals.

# S3 method for integer
cut(x, ...)

Arguments

x

integer vector

...

further arguments passed to or from other methods

Value

If cut.default(x, ...) returns only integer intervals, these are formatted in a more natural way and returned as an ordered factor. If non integer interval limits occur, the output of cut.default(x, ...) is returned as is.

Examples

cut.default(1:100, seq(0, 100, 20)) # Gives a quite unnatural output
#> [1] (0,20] (0,20] (0,20] (0,20] (0,20] (0,20] (0,20] (0,20] #> [9] (0,20] (0,20] (0,20] (0,20] (0,20] (0,20] (0,20] (0,20] #> [17] (0,20] (0,20] (0,20] (0,20] (20,40] (20,40] (20,40] (20,40] #> [25] (20,40] (20,40] (20,40] (20,40] (20,40] (20,40] (20,40] (20,40] #> [33] (20,40] (20,40] (20,40] (20,40] (20,40] (20,40] (20,40] (20,40] #> [41] (40,60] (40,60] (40,60] (40,60] (40,60] (40,60] (40,60] (40,60] #> [49] (40,60] (40,60] (40,60] (40,60] (40,60] (40,60] (40,60] (40,60] #> [57] (40,60] (40,60] (40,60] (40,60] (60,80] (60,80] (60,80] (60,80] #> [65] (60,80] (60,80] (60,80] (60,80] (60,80] (60,80] (60,80] (60,80] #> [73] (60,80] (60,80] (60,80] (60,80] (60,80] (60,80] (60,80] (60,80] #> [81] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100] #> [89] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100] (80,100] #> [97] (80,100] (80,100] (80,100] (80,100] #> Levels: (0,20] (20,40] (40,60] (60,80] (80,100]
cut(1:100, seq(0, 100, 20)) # Gives nicer and ordered output
#> [1] 1-20 1-20 1-20 1-20 1-20 1-20 1-20 1-20 1-20 1-20 #> [11] 1-20 1-20 1-20 1-20 1-20 1-20 1-20 1-20 1-20 1-20 #> [21] 21-40 21-40 21-40 21-40 21-40 21-40 21-40 21-40 21-40 21-40 #> [31] 21-40 21-40 21-40 21-40 21-40 21-40 21-40 21-40 21-40 21-40 #> [41] 41-60 41-60 41-60 41-60 41-60 41-60 41-60 41-60 41-60 41-60 #> [51] 41-60 41-60 41-60 41-60 41-60 41-60 41-60 41-60 41-60 41-60 #> [61] 61-80 61-80 61-80 61-80 61-80 61-80 61-80 61-80 61-80 61-80 #> [71] 61-80 61-80 61-80 61-80 61-80 61-80 61-80 61-80 61-80 61-80 #> [81] 81-100 81-100 81-100 81-100 81-100 81-100 81-100 81-100 81-100 81-100 #> [91] 81-100 81-100 81-100 81-100 81-100 81-100 81-100 81-100 81-100 81-100 #> Levels: 1-20 < 21-40 < 41-60 < 61-80 < 81-100
cut(1:10, 3) # no integer intervals and therefor same as cut.default
#> [1] (0.991,4] (0.991,4] (0.991,4] (0.991,4] (4,7] (4,7] (4,7] #> [8] (7,10] (7,10] (7,10] #> Levels: (0.991,4] (4,7] (7,10]