Skip to contents

This function lets the user quickly calculate cuts for quantiles and discretize numerical values into categorical values.

Usage

quants(values, splits = 10, return = "labels", n = 2)

Arguments

values

Vector. Values to calculate quantile cuts

splits

Integer. How many cuts should split the values?

return

Character. Return "summary" or "labels"

n

Integer. Determines the number of digits used in formatting the break numbers.

Value

Factor vector or data.frame. Depending on return input:

  • labels a factor ordered vector with each observation's quantile

  • summary a data.frame with information on each quantile cut

Examples

data(dft) # Titanic dataset
quants(dft$Age, splits = 5, "summary")
#>      percentile  cut   label
#> 20%         20% 19.0 [19-19]
#> 40%         40% 25.0 (19-25]
#> 60%         60% 31.8 (25-32]
#> 80%         80% 41.0 (32-41]
#> 100%       100% 80.0 (41-80]
quants(dft$Age, splits = 5, "labels")[1:10]
#>  [1] (19,25]   (32,41]   (25,32]   (32,41]   (32,41]   <NA>      (41,80]  
#>  [8] [0.42,19] (25,32]   [0.42,19]
#> Levels: [0.42,19] < (19,25] < (25,32] < (32,41] < (41,80]