raster (version 1.1.7)

stats: Miscellaneous statistical functions

Description

mode and coefficient of variation

Usage

modal(x, ..., ties='random', na.rm = FALSE)
cv(x, ..., aszero=FALSE, na.rm = FALSE)

Arguments

x
A vector of numbers (typically integers for modal)
...
additional (vectors of) numbers
ties
character. Indicates how to treat ties. Either 'random', 'lowest', 'highest', or 'NA'
na.rm
Remove (ignore) NA values
aszero
logical. If TRUE, a zero is returned (rather than an NA) if the cv of single value is computed

Value

  • modal returns the mode, or modal (most frequent) value of a vector of values, ties are broken at random. cv returns the coefficient of variation (expressed as a percentage). If there is only a single value, sd is NA and cv returns NA if aszero=FALSE (the default). However, if (aszero=TRUE), cv returns 0.

Examples

Run this code
data <- c(0,1,2,3,3,3,3,4,4,4,5,5,6,7,7,8,9,NA)
modal(data, na.rm=TRUE)
cv(data, na.rm=TRUE)

Run the code above in your browser using DataCamp Workspace