
Last chance! 50% off unlimited learning
Sale ends in
CutQ(x, breaks = quantile(x, seq(0, 1, by = 0.25), na.rm = TRUE),
labels = NULL, na.rm = FALSE, ...)
quantile
seq(0, 1, by = 0.25)
quantiles. See quantile
for details.Q1
, Q2
to the length of breaks - 1. The parameter ist passed to cut
, so if labels
are secut
.q
.quantile
to obtain the specified
quantiles of x
, then calls cut
to create a factor
variable using the intervals specified by these quantiles.
It properly handles cases where more than one quantile obtains the
same value, as in the second example below. Note that in this case,
there will be fewer generated factor levels than the specified number
of quantile intervals.cut
, quantile
# create example data
<testonly>set.seed(1234)</testonly>
x <- rnorm(1000)
# cut into quartiles
quartiles <- CutQ(x)
table(quartiles)
# cut into deciles
deciles <- CutQ(x, seq(0, 1, by=0.1), labels=NULL)
table(deciles)
# show handling of 'tied' quantiles.
x <- round(x) # discretize to create ties
stem(x) # display the ties
deciles <- CutQ( x, seq(0, 1, by=0.1) )
table(deciles) # note that there are only 5 groups (not 10)
# due to duplicates
Run the code above in your browser using DataLab