Learn R Programming

DescTools (version 0.99.6)

CutQ: Build Quantile Groups for a Numeric Variable

Description

Divides the range of x into some quantiles and codes the values in x according to which interval they fall.

Usage

CutQ(x, quant = c(.25,.5,.75,1), labels = gettextf("Q%s", 1:4), na.rm = FALSE)

Arguments

x
a numeric vector which is to be converted to a factor by cutting.
quant
the breaks for the quantiles, default is quartiles.
labels
labels for the levels of the resulting category. By default, labels are defined as Q1, Q2, Q3 and Q4. The parameter ist passed to cut, so if labels = FALSE, s
na.rm
logical, indicating whether NA values should be stripped before the computation of the quantile proceeds. Defaults to FALSE. NAs are reported as NA afterwards.

Value

  • A factor is returned, unless labels = FALSE which results in an integer vector of level codes.

See Also

cut, quantile

Examples

Run this code
boxplot(temperature ~ CutQ(temperature, na.rm = TRUE), data=d.pizza)

Run the code above in your browser using DataLab