r - How to find the statistical mode? - Stack Overflow
What is mode?
What is the notation for calculating the mode? - Mathematics Stack Exchange
What is the purpose of the "mode" in statistics?
Videos
One more solution, which works for both numeric & character/factor data:
Mode <- function(x) {
ux <- unique(x)
ux[which.max(tabulate(match(x, ux)))]
}
On my dinky little machine, that can generate & find the mode of a 10M-integer vector in about half a second.
If your data set might have multiple modes, the above solution takes the same approach as which.max, and returns the first-appearing value of the set of modes. To return all modes, use this variant (from @digEmAll in the comments):
Modes <- function(x) {
ux <- unique(x)
tab <- tabulate(match(x, ux))
ux[tab == max(tab)]
}
found this on the r mailing list, hope it's helpful. It is also what I was thinking anyways. You'll want to table() the data, sort and then pick the first name. It's hackish but should work.
names(sort(-table(x)))[1]
One possibility for the notation for a mode is $$\underset{x}{\operatorname{arg\,max}} f(x)$$ but I thought that was ugly, so here I used a hat $$\hat{X}$$ to indicate the peak in the probability density or mass function, even though this can also be used for other meanings.
In Bayesian estimation, the mode is given by the maximum a posteriori (MAP) estimate. Using the "MAP" subscript would suffice.