modal.value = function (x, na.rm) { xtab <- table(x) xmode <- names(which(xtab == max(xtab))) if (length(xmode) > 1) warning("There is more than one modal value!") return(ifelse(is.numeric(x), as.numeric(xmode), as.character(x.mode))) }