sampleMode: Get the sample mode of a vector or matrix.

View source: R/sampleMode.R

sampleModeR Documentation

Get the sample mode of a vector or matrix.

Description

Return the most common value in a sample or, for numerix x with no duplicate values, return the maximum density estimate.

Usage

sampleMode(x, na.rm = FALSE)

Arguments

x

A vector or matrix.

na.rm

If TRUE, remove NAs from x, if FALSE (default) retain them.

Details

Returns the mode (most common value) of a vector or matrix or, for numerix x with no duplicate values, return the maximum density estimate. For non-numeric x with no duplicates return NA. When there is more than 1 mode, return the one whose value occurs first in x.

Value

A single value corresponding to the most common value in x.

Author(s)

David Braze davebraze@gmail.com

Examples

x0 <- sample(1:26, 5000, replace=TRUE)
sampleMode(x0)

x1 <- sample(letters, 5000, replace=TRUE)
sampleMode(x1)

x2 <- rnorm(100000, m=9.5)
sampleMode(x2)

davebraze/FDButils documentation built on Feb. 24, 2023, 12:14 a.m.