Skip to contents

Compute the *mode* of a vector, i.e. the value that has highest number of occurrences. If different values have the same number of occurrences, the first one is reported.

Usage

modalValue(x, i = NULL, na.rm = TRUE)

Arguments

x

(named) numerical vector

i

(optional) numerical vector giving the position in x or character vector matching the names in x. If missing or i = NULL, the entire x is considered for the computation of the score

na.rm

logical, whether to remove NA values from x before computation

Value

A length-one numerical vector.

Author

Alessandro Barberis

Examples

x = c(1,1,2,3,3,3,NA)
modalValue(x = x, na.rm = TRUE)
#> [1] 3