mode_average: Function to calculate mode (the value that appears most...

View source: R/mode_average.R

mode_averageR Documentation

Function to calculate mode (the value that appears most often) of a vector.

Description

Function to calculate mode (the value that appears most often) of a vector.

Usage

mode_average(x, na.rm = FALSE)

Arguments

x

Input vector.

na.rm

Should NAs be omitted?

Value

Vector with a length of 1.

Author(s)

Ken Williams.

See Also

stackoverflow, mean, median

Examples


# Calculate the mode of integers
mode_average(c(1L, 2L, 3L, 3L))

# Calculate the mode of a numeric vector
mode_average(c(5, 6, 6, 500000))

# Will return the first element when one or two elements are supplied
mode_average(c(5, 1))
mode_average(c("hail", "rain"))

# Will also work with character and factor vectors
mode_average(c("rain", "hail", "sunshine", "rain"))


skgrange/threadr documentation built on May 11, 2024, 12:16 p.m.