cutp: Cut a numeric vector into quantiles

View source: R/cutp.R

cutpR Documentation

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, ...)

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.

Value

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

#' @seealso quantile; cut

Examples

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


tldr documentation built on May 31, 2023, 9:02 p.m.

Related to cutp in tldr...