R/example-fn.R

Defines functions mode

Documented in mode

#------------------------------------------------
#' Arithmetic Mode
#'
#' Compute the arithmetic mode of a set of data. The mode is the most commonly
#' appearing value.
#'
#' @param x A vector or list.
#'
#' @return The mode of the input.
#' @export
#' @examples
#' mode(c(1, 1, 2))
#' mode(list(1, 1, 2))
#' mode(c(1, NA, 1))
mode <- function(x) {
  unique <- unique(x)
  unique[which.max(tabulate(match(x, unique)))]
}
arisp99/testactionspkg documentation built on Nov. 14, 2024, 9:33 p.m.