Learn R Programming

statoo (version 0.1.3)

mfv: Most frequent value(s)

Description

The function mfv returns the most frequent value(s) (or mode(s)) found in a vector. The function mfv1 returns the first of these values, so that mfv1(x) is identical to mfv(x)[[1L]].

Usage

mfv(x, ...)
mfv1(x, ...)

Arguments

x
Vector of observations (of type numeric, character, factor, or logical).
...
Additional parameters that are currently ignored.

Value

The function mfv returns a vector of the same type as x. One should be aware that this vector can be of length > 1, in case of multiple modes. mfv1 is safer in the sense that it always returns a vector of length 1 (the first of the modes found).

Details

Argument x is to come from a discrete distribution. mfv calls the function tabulate.

References

  • Dutta S. and Goswami A. (2010). Mode estimation for discrete distributions. Mathematical Methods of Statistics, 19(4):374--384.

Examples

Run this code
# Basic examples
mfv(c(3, 4, 3, 2, 2, 1, 2))      # 2
mfv(c(TRUE, FALSE, TRUE))        # TRUE
mfv(c("a", "a", "b", "a", "d"))  # "a"

mfv(c("a", "a", "b", "b", "d"))  # c("a", "b")
mfv1(c("a", "a", "b", "b", "d")) # "a"

Run the code above in your browser using DataLab