Creates a factor based on equally spaced quantiles of a variable.

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

Arguments

data

A numeric vector.

n

An integer specifying the number of levels in the factor to be created.

na.rm

A logical vector indicating whether the NA values should be removed before the quantiles are computed.

Value

A vector of class factor indicating in which quantile the element in data belongs.

See also

Examples

x <- c(sample(1:20, 9), NA) divide_by_quantile(x, 3)
#> [1] 3 1 2 1 3 1 3 2 2 <NA> #> Levels: 1 2 3