Mode: Mode of a vector

Description Usage Arguments Details Value Author(s) Examples

View source: R/predProbs.r

Description

Finds the modal value of a vector of any class.

Usage

1
Mode(x, na.rm = FALSE)

Arguments

x

a vector (lists and arrays will be flattened).

na.rm

logical: strip NA values?

Details

Based on the Stack Overflow answer http://stackoverflow.com/a/8189441/143383

Value

The value of x that occurs most often. If there is a tie, the one that appears first (among those tied) is chosen.

Author(s)

Ken Williams (on Stack Overflow)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
x <- c(1, 3, 3, 4)
Mode(x)  # 3
x.char <- letters[x]
Mode(x.char)  # "c"
x.factor <- as.factor(x.char)
Mode(x.factor)  # "c", with levels "a", "c", "d"
x.logical <- x > 3
Mode(x.logical)  # FALSE

## Behavior with ties
y <- c(3, 3, 1, 1, 2)
Mode(y)  # 3
z <- c(2, 1, 1, 3, 3)
Mode(z)  # 1

games documentation built on May 2, 2019, 3:26 p.m.