cut_quantile: Cutting a Numeric Vector into a Factor of Quantile Bins

View source: R/utils.R

cut_quantileR Documentation

Cutting a Numeric Vector into a Factor of Quantile Bins

Description

[Experimental]

This function transforms a numeric vector into a factor corresponding to the quantile intervals. The intervals are left-open and right-closed.

Usage

cut_quantile(x, percentiles = c(1/3, 2/3), digits = 0)

Arguments

x

(numeric)
the continuous variable values which should be cut into quantile bins. NA values are not taken into account when computing quantiles and are attributed to the NA interval.

percentiles

(proportions)
the required percentiles for the quantile intervals to be generated. Duplicated values are removed.

digits

(integer)
the precision to use when formatting the percentages.

Value

The factor with a description of the available quantiles as levels.

Examples

set.seed(452)
x <- runif(10, -10, 10)
cut_quantile(x, c(0.33333333, 0.6666666), digits = 4)

x[1:4] <- NA
cut_quantile(x)

insightsengineering/hermes documentation built on Sept. 19, 2024, 9:06 p.m.