One possibility for the notation for a mode is but I thought that was ugly, so here I used a hat
to indicate the peak in the probability density or mass function, even though this can also be used for other meanings.
What is mode?
What is the notation for calculating the mode? - Mathematics Stack Exchange
r - How to find the statistical mode? - Stack Overflow
What is the purpose of the "mode" in statistics?
How to find mode for given set of values?
What is mode in statistics?
Can there be two modes in a given set of data?
Videos
One possibility for the notation for a mode is but I thought that was ugly, so here I used a hat
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.
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]