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, ...)
x | a vector. |
---|---|
... | additional parameters passed on to |
a scalar equal to the modal value of x
. If
x
is multimodal, length(x)
will equal the number
of unique modes in x
.
http://mathworld.wolfram.com/Mode.html
x <- c(0, 1, 2, 3, 4, 5, 0) y <- c("foo", "bar", "baz", "foo") z <- factor(y) most_freq(x)#> [1] 0most_freq(y)#> [1] "foo"most_freq(z)#> [1] foo #> Levels: fooxx <- c(1, x) most_freq(xx)#> [1] 0 1