R/statistical_mode.R

Defines functions statistical_mode

Documented in statistical_mode

#' @title Statistical mode of a vector
#' @description Computes the mode of a numeric or character vector
#' @param x Numeric or character vector.
#' @return Statistical mode of `x`.
#' @examples
#' if(interactive()){
#'
#'  statistical_mode(c(10, 9, 10, 8))
#'
#' }
#' @rdname statistical_mode
#' @export
statistical_mode <- function(x){

  x.unique <- unique(x)

  x.unique[which.max(tabulate(match(x, x.unique)))]

}

Try the spatialRF package in your browser

Any scripts or data that you put into this service are public.

spatialRF documentation built on Aug. 19, 2022, 5:23 p.m.