Calculate most frequently occuring value in a vector (statistical mode).

most_freq(x, ...)

# S3 method for numeric
most_freq(x, ...)

# S3 method for character
most_freq(x, ...)

# S3 method for factor
most_freq(x, ...)

Arguments

x

a vector.

...

additional parameters passed on to table.

Value

a scalar equal to the modal value of x. If x is multimodal, length(x) will equal the number of unique modes in x.

References

http://mathworld.wolfram.com/Mode.html

Examples

x <- c(0, 1, 2, 3, 4, 5, 0) y <- c("foo", "bar", "baz", "foo") z <- factor(y) most_freq(x)
#> [1] 0
most_freq(y)
#> [1] "foo"
most_freq(z)
#> [1] foo #> Levels: foo
xx <- c(1, x) most_freq(xx)
#> [1] 0 1