math_mode: Mathematical Mode

View source: R/metrics.R

math_modeR Documentation

Mathematical Mode

Description

Obtain the most frecuent values (mode) with the frequency from a vector. By default all values with the greatest frequency are returned but you can limit the result to the first one, in lexicographical order.

Usage

math_mode(x, remove_na = TRUE, allow_multimodal = TRUE)

Arguments

x

(factor) A vector of values to compute the mode.

remove_na

(logical(1)) Should NA values be removed and not include them in the frequencies counting? TRUE by default.

allow_multimodal

(logical(1)) If there is more than one mode, should all the most frequent values be returned? TRUE by default.

Value

A character vector with the most frequent values if allow_multimodal is TRUE or the first most frequent value (after ordering lexicographically) if allow_multimodal is FALSE.

The returned vector contains the attribute "frequency" with an integer of the greatest frequency.

See Also

Other categorical_metrics: accuracy(), brier_score(), categorical_summary(), confusion_matrix(), f1_score(), kappa_coeff(), matthews_coeff(), pccc(), pcic(), pr_auc(), precision(), recall(), roc_auc(), sensitivity(), specificity()

Examples

## Not run: 
# Multimodal
x <- math_mode(c("C", "A", "C", "A"))
# Obtain the greatest frequency
attr(x, "frequency")

# Single mode
x <- math_mode(c("C", "A", "C", "A"), allow_multimodal = FALSE)

# Multimodal
x <- math_mode(iris$Species)
attr(x, "frequency")

values <- c("A", "B", NA, "C", "A", NA, "B")
# Multimodal without NAs
x <- math_mode(values)
# Multimodal with NAs
x <- math_mode(values, remove_na = FALSE)

## End(Not run)


brandon-mosqueda/SKM documentation built on Feb. 8, 2025, 5:24 p.m.