cut_quantile: Convert numeric to factor with intervals of equal number of...

View source: R/cut_quantile.R

cut_quantileR Documentation

Convert numeric to factor with intervals of equal number of items by using quantiles

Description

cut_quantile() is like cut(), but it calculates intervals from quantiles such that each interval has approximately the same number of items from the original vector. x must have both quantile() and cut() methods implemented.

Usage

cut_quantile(x, breaks, labels = NULL, ...)

Arguments

x

An R object, usually a numeric vector.

breaks

A single integer with the number of breaks to use.

labels

Labels for the resulting category or NULL (by default) to construct them automatically like "(a,b]". If labels = FALSE, simple integer codes are returned instead of factor.

...

Further arguments passed to cut().

Value

A factor() is returned, unless labels = FALSE (in this case, a integer vector is obtained).

Examples

# Transform a numeric vector into a factor with 5 levels of same item numbers
vec <- rnorm(20)
fact <- cut_quantile(vec, breaks = 5)
fact
table(fact)

SciViews/svMisc documentation built on Sept. 15, 2023, 3:51 a.m.