quantile_group {basecamb}R Documentation

Stratify a numeric vector into quantile groups

Description

Transforms a numeric vector into quantile groups. For each input value, the output value corresponds to the quantile that value is in. When grouping into n quantiles, the lowest 1/n of values are assigned 1, the highest 1/n are assigned n.

Usage

quantile_group(data, n, na.rm = TRUE)

Arguments

data

a vector of type numeric with values to be grouped into quantiles

n

integer indicating number of quantiles, minimum of 2. Must be smaller than length(data)

na.rm

logical; if TRUE all NA values will be removed before calculating groups, if FALSE no NA values are permitted.

Details

Tied values will be assigned to the lower quantile group rather than etsimating a distribution. In extreme cases this can mean one or more quantile groups are not represented.

If uneven group sizes cannot be avoided, values will be assigned the higher quantile group.

Value

vector of length length(data) with the quantile groups

Author(s)

J. Peter Marquardt

Examples

quantile_group(10:1, 3)
quantile_group(c(rep(1,3), 10:1, NA), 5)


[Package basecamb version 1.1.5 Index]