Skip to contents

Cut a numeric vector into intervals.

Usage

cut_quantile(x, n = 4, labels = NULL)

cut_length(x, n = 4, labels = NULL)

cut_breaks(x, breaks = NULL, labels = NULL, right = TRUE)

Arguments

x

A numeric vector.

n

A positive integer. The number of intervals.

labels

labels for the levels of the resulting category. By default, labels are constructed using "(a,b]" interval notation. If labels = FALSE, simple integer codes are returned instead of a factor.

breaks

either a numeric vector of two or more unique cut points or a single number (greater than or equal to 2) giving the number of intervals into which x is to be cut.

right

logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa.

Value

Print the selected rows of the data. Return the input data frame invisibly.

Examples

cut_quantile(1:20)
#>  [1] [1,5.75]    [1,5.75]    [1,5.75]    [1,5.75]    [1,5.75]    (5.75,10.5]
#>  [7] (5.75,10.5] (5.75,10.5] (5.75,10.5] (5.75,10.5] (10.5,15.2] (10.5,15.2]
#> [13] (10.5,15.2] (10.5,15.2] (10.5,15.2] (15.2,20]   (15.2,20]   (15.2,20]  
#> [19] (15.2,20]   (15.2,20]  
#> Levels: [1,5.75] < (5.75,10.5] < (10.5,15.2] < (15.2,20]

cut_length(1:20)
#>  [1] [1,5.75]    [1,5.75]    [1,5.75]    [1,5.75]    [1,5.75]    (5.75,10.5]
#>  [7] (5.75,10.5] (5.75,10.5] (5.75,10.5] (5.75,10.5] (10.5,15.2] (10.5,15.2]
#> [13] (10.5,15.2] (10.5,15.2] (10.5,15.2] (15.2,20]   (15.2,20]   (15.2,20]  
#> [19] (15.2,20]   (15.2,20]  
#> Levels: [1,5.75] < (5.75,10.5] < (10.5,15.2] < (15.2,20]

cut_breaks(1:20, breaks = c(5, 15))
#>  [1] [1,5]   [1,5]   [1,5]   [1,5]   [1,5]   (5,15]  (5,15]  (5,15]  (5,15] 
#> [10] (5,15]  (5,15]  (5,15]  (5,15]  (5,15]  (5,15]  (15,20] (15,20] (15,20]
#> [19] (15,20] (15,20]
#> Levels: [1,5] < (5,15] < (15,20]