#' Calculate the modus
#'
#' @param var A atomic vector
#' @importFrom checkmate assert_atomic_vector
#' @keywords internal
modus <- function(var) {
# input checks
assert_atomic_vector(var, all.missing=FALSE, min.len=1)
# calculate modus
freqs <- table(var)
mod <- names(freqs)[which.max(freqs)]
# factors should be returned as factors with all factor levels
if(is.factor(var)) {
mod <- factor(mod, levels=levels(var))
}
return(mod)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.