R/getmode.R

Defines functions getmode

Documented in getmode

#' Get the mode from a vector
#'
#' @param v A vector
#'
#' @return A vector containing the most frequent value in a vector.
#' If there is a tie, the top values will be returned.
#' R currently has no built-in function to get mode
#'
#' @export
#'
#' @examples
#' hps <- mtcars$hp
#' getmode(hps)
getmode <- function(v) {
  uniqv <- unique(v)
  uniqv[which.max(tabulate(match(v, uniqv)))]
}
Aypak/dbhelpers documentation built on Jan. 25, 2024, 9:03 p.m.