Learn R Programming

lsr (version 1.0.0)

quantileCut: Cut by quantiles

Description

Divides a numeric variable into n categories that each contain approximately the same number of observations.

Usage

quantileCut(x, n, ...)

Value

A factor with n levels. Level labels follow the same convention as cut and can be overridden with the labels argument.

Arguments

x

A numeric vector.

n

The number of categories to create.

...

Additional arguments passed to cut, such as labels.

Details

Unlike cut, which creates categories of equal width, quantileCut uses quantile to find breakpoints that produce roughly equal-sized groups. This can be useful in exploratory analysis, but the resulting categories are data-driven and may not have a clear interpretation. Using them as grouping variables in an ANOVA is generally not recommended, as the breakpoints are arbitrary and the groups will typically not have equal variances.

See Also

Examples

Run this code
# the data are unevenly spread, so equal-width bins would be unbalanced
x <- c(0, 1, 2, 3, 4, 5, 7, 10, 15)

# quantileCut creates equal-frequency bins
bins_eq_freq <- quantileCut(x, 3)
table(bins_eq_freq)

# compare to cut(), which creates equal-width bins
bins_eq_width <- cut(x, 3)
table(bins_eq_width)

Run the code above in your browser using DataLab