mode_stat: Mode (as in statistical 'mode') function

View source: R/mode_stat.R

mode_statR Documentation

Mode (as in statistical 'mode') function

Description

Calculates the mode of x.

Usage

mode_stat(x)

Arguments

x

input vector

Details

In case of ties, or if length(x) == 1, will return the first value. The standard caveats apply to floats; see examples.

Value

The most frequent value in x, or see details for exception cases. Will throw a warning if length(unique(x) == length(x)).

Note

Credit: http://stackoverflow.com/questions/2547402/is-there-a-built-in-function-for-finding-the-mode

Examples

mode_stat(sample(1:10, 100, replace = TRUE))
mode_stat(sample(LETTERS[1:3], 20, replace = TRUE))

## Not run: 
set.seed(1)
x <- rnorm(100)
x[1] == mode_stat(x)
x <- signif(x, 2)
x[1] == mode_stat(x) #better, but note about ties applies

## End(Not run)

slin30/wzMisc documentation built on Jan. 27, 2023, 1 a.m.