R: how to find the mode of a vector [duplicate]

This post provides an elegant function to determine the mode so all you need to do is apply it to your data frame.

Mode <- function(x) {
  ux <- unique(x)
  ux[which.max(tabulate(match(x, ux)))]
}

apply(d, 2, Mode)

Yields:

MEMORY1 MEMORY2 MEMORY3 MEMORY4 MEMORY5 MEMORY6 MEMORY7 MEMORY8 
    5.5     5.5     4.5     1.5     4.5     5.5     4.5     5.5 

Leave a Comment