modus: Modus of a variable

Description Usage Arguments Details Value Examples

Description

Get the modus of a variable, i. e. the value that is most frequent in an variable (can be numeric and character)

Usage

1
modus(variable, useNA = "no", equal.dist = 99)

Arguments

variable

The variable containing

useNA

Should NAs be used? Will be passed on to table. Can be either "no", "ifany", or "always".

equal.dist

If all entries are equally often, this value will be returned as output. Default is to 99.

Details

If two (not all) values are equally often in the variable, the first value of these will be returned. A message is issued.

Value

The modus will be returned.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
letter_samp <- sample(letters, 50, TRUE)
modus(letter_samp)
##
set.seed(9)
m <- matrix(sample(1:5, 30, replace=TRUE), 10, 3, byrow=TRUE)
m[c(23, 12)] <- NA
m[c(4)] <- 1 # no variance
data <- as.data.frame(m)
apply(data, 1, modus)
##
# message, since 2 and 3 are equally often.
modus(c(2, 2, 2, 3, 3, 3, 4, 4))

kthorstmann/horst documentation built on May 20, 2019, 7:04 p.m.