cutp | R Documentation |
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.
cutp(x, p, ...)
x |
A numeric vector to be discretized |
p |
A numeric vector of probabilities |
... |
Arguments passed to 'cut' |
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.
Returns the output from 'cut'. This is usually a factor unless otherwise specified.
#' @seealso quantile
; cut
myvals = rnorm(1000)
catx = cutp(x=myvals, p=c(0.25, 0.5, 0.75), labels=c('Q1', 'Q2', 'Q3', 'Q4'))
table(catx)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.