Learn R Programming

BBmisc (version 1.13)

computeMode: Compute statistical mode of a vector (value that occurs most frequently).

Description

Works for integer, numeric, factor and character vectors. The implementation is currently not extremely efficient.

Usage

computeMode(x, ties.method = "random", na.rm = TRUE)

Value

Modal value of length 1, data type depends on data type of x.

Arguments

x

[vector]
Factor, character, integer, numeric or logical vector.

ties.method

[character(1)]
“first”, “random”, “last”: Decide which value to take in case of ties. Default is “random”.

na.rm

[logical(1)]
If TRUE, missing values in the data removed. if FALSE, they are used as a separate level and this level could therefore be returned as the most frequent one. Default is TRUE.

Examples

Run this code
computeMode(c(1,2,3,3))

Run the code above in your browser using DataLab