get_levels: Get map of levels in numeric vector

View source: R/utils.R

get_levelsR Documentation

Get map of levels in numeric vector

Description

Maps the values in a numeric vector as quantiles, default is low, intermediate, and high,

Usage

get_levels(v, n_quantiles = 3, add = NA, return_num = F)

Arguments

v

A numeric vector

n_quantiles

Number of quantiles/levels to separate v by. Default 3. Minimum 2.

add

A string to add to the beginning of each levels in the result, e.g If add is "gene", the result will be "gene.low", "gene.int", gene.high"

return_num

Logical indicating whether to return the number of quantile or not

levels

A list of 3 elements (l, i, h) representing quantiles, default is 1 = low, 2 = intermediate, 3 = high. If n_quantiles > 3, the "middle" levels will be "int", "int.plus", "int.plus.plus" and so on. Note: If "LEVELS" is defined in global environment, this variable will be used.

Value

A vector with the same length as v, where each element represents the quantile, either in numeric form (if return_num is TRUE) or characters with the legend represented by the levels parameter

Examples

get_levels(1:9)
# [1] "low"      "low"      "low"      "intermed" "intermed" "intermed" "high"     "high"     "high"
get_levels(1:9, return_num = T)
# [1] 1 1 1 2 2 2 3 3 3

kazeera/hourglass documentation built on April 5, 2025, 7:18 a.m.