Learn R Programming

tldr (version 0.3.0)

cutp: Cut a numeric vector into quantiles

Description

cutp is a wrapper for the base `cut` function. The vector `x` will be categorized using the percentiles provided in `p` to create break values.

Usage

cutp(x, p, ...)

Value

Returns the output from `cut`. This is usually a factor unless otherwise specified.

#' @seealso quantile; cut

Arguments

x

A numeric vector to be discretized

p

A numeric vector of probabilities

...

Arguments passed to `cut`

Details

Within the `cutp` function, `p` is passed to `quantile` as the `probs` input. The computed quantiles are then used as the `breaks` in `cut`.

The values `-Inf` and `Inf` are added to the beginning and end of the breaks vector, respectively, so quantiles for 0 and 1 do not need to be given explicitly.

Examples

Run this code
myvals = rnorm(1000)
catx = cutp(x=myvals, p=c(0.25, 0.5, 0.75), labels=c('Q1', 'Q2', 'Q3', 'Q4'))
table(catx)

Run the code above in your browser using DataLab