Mode: Mode

Description Usage Arguments Value Note Author(s) See Also Examples

View source: R/StatsAndCIs.r

Description

Calculates the mode, the most frequent value, of a variable x. This makes mostly sense for qualitative data.

Usage

1
Mode(x, na.rm = FALSE)

Arguments

x

a (non-empty) numeric vector of data values.

na.rm

logical. Should missing values be removed? Defaults to FALSE.

Value

Returns the most frequent value. If there are more than one, all of them are returned in a vector.

Note

Consider using density(x)$x[which.max(density(x)$y)] for quantitative data or alternatively use hist().
Another interesting idea:

1
2
3
4
5
6
peak <- optimize(function(x, model) predict(model, data.frame(x = x)),
                 c(min(x), max(x)),
                 maximum = TRUE,
                 model = y.loess) 
            
points(peak$maximum, peak$objective, pch=FILLED.CIRCLE <- 19) 

Author(s)

Andri Signorell <andri@signorell.net>

See Also

mean, median

Examples

1
2
3
4
5
data(d.pizza)
Mode(d.pizza$driver)

# use sapply for evaluating data.frames (resp. apply for matrices)
sapply(d.pizza[,c("driver","temperature","date")], Mode, na.rm=TRUE)

DescTools documentation built on May 19, 2017, 1:25 p.m.

Search within the DescTools package
Search all R packages, documentation and source code