mode: Find the Mode of a Distribution

Description Usage Arguments Value Note Author(s) Examples

Description

Returns the modal value of a set of numerical or categorical values.

Usage

1
mode(x, na.rm = FALSE)

Arguments

x

A vector.

na.rm

If TRUE (default) observations with a missing value of x are removed before applying the test.

Value

Returns the modal value (category)

Note

Modified version of http://stackoverflow.com/questions/2547402/is-there-a-built-in-function-for-finding-the-mode that is able to handled tied modal categories.

Author(s)

Paul Williamson

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Find modal category of a categorical variable
mode(survey$Age)

## Tied modal values
mode(c(1, 2, 2, 3, 3, 4))

## Default handling of missing values
mode( c(1, 2, 3, 3, NA, NA, NA) )

## Mode excluding missing values
mode( c(1, 2, 3, 3, NA, NA, NA), na.rm=TRUE)

DrPaulWilliamson/ENVS450 documentation built on May 9, 2019, 3:23 a.m.