Learn R Programming

KODAMA (version 0.0.1)

majority: Determines Majority Class

Description

This is function determines the majority class of a vector (treated as factor).

Usage

majority(x)

Arguments

x
a vector.

Value

The factor level which occurs most often in x.

Details

This function treats the input vector as a factor and determines which level (class) of the factor is present most often. If two or more levels tie for majority then a random selection is made among the ties.

See Also

factor

Examples

Run this code
x <- sample(c("a","b","c","d","e","f"), 10, replace=TRUE)
majority(x)

Run the code above in your browser using DataLab