cutp {tldr} | R 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.
Examples
myvals = rnorm(1000)
catx = cutp(x=myvals, p=c(0.25, 0.5, 0.75), labels=c('Q1', 'Q2', 'Q3', 'Q4'))
table(catx)
[Package tldr version 0.4.0 Index]