# Roger Palay copyright 2016-01-31 # Saline, MI 48176 # Mode <- function(x, display=TRUE, na.rm = FALSE) { ## taken from a post by Ken Williams on Stackoverflow, ## and modified with other ideas and suggestions there, ## and then tuned by R. Palay for a speific use here. if(na.rm) {x = x[!is.na(x)] } ux <- unique(x) tab <- tabulate(match(x, ux)) um <- max(tab) uy<-ux[tab == um] uy=sort(uy) if( display ) {cat("Mode Frequency=",um,"Mode Value(s)=",uy,"\n")} c(um,uy) }