Skip to contents

This function calculates the mode of a given numeric vector.

Usage

get_mode(x)

Source

The source of this function was taken from this link.

Arguments

x

Numeric vector. It must not be NULL or empty.

Value

The mode of the vector as a single value. If the vector has a uniform distribution (all values appear with the same frequency), the function returns the first value encountered.

Examples

get_mode(c(seq_len(10), 1, 1, 3, 3, 3, 3))
#> [1] 3

get_mode(c(1, 2, 2, 3, 4))
#> [1] 2

get_mode(c(1, 1, 2, 3, 3))
#> [1] 1