Re: [S] distributional mode

Prof Brian Ripley (
Tue, 1 Sep 1998 13:55:12 +0100 (BST)

> From: Mike Richman <>
> We know that the Splus command "mode" does not give the statistical
> mode of a distribution. I've been kludging the table command. What
> I'm after (if possible) is a command one can use with "apply" to give
> the statistical mode of the rows/columns of a matrix. Anyone have a
> simple solution?

What is the `statistical mode', presumably of a vector? I know what a
mode of a density is (but not of a distribution: it depends on the base
measure). Unless you have discrete data I think this is meaningless.
IF you do and `mode' means most frequently occurring value:

discmode <- function(x)
z <- table(x)
as.numeric(names(z)[z == max(z)])

will give all the modes (there could be more than one). To use with apply
you really need to tell us how to get a unique answer (unless you like
interpreting lists, which is what apply will give).

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

----------------------------------------------------------------------- This message was distributed by To unsubscribe send e-mail to with the BODY of the message: unsubscribe s-news