[R] statistical mode function
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Aug 24 14:25:10 CEST 2001
On Fri, 24 Aug 2001, Elena MOLTCHANOVA wrote:
> Hello R-users,
>
> I am aware that this is a very basic question, but still... Since mode()
> function is reserved for something else, is there a function to calculate
> statistical mode for a vector or a matrxi?
>
> i.e. mode.function(c(1,2,2,2,3,3))=2
If that is to be regarded as a discrete distribution,
statmod <- function(x) {
z <- table(as.vector(x))
names(z)[z == max(z)]
}
should do the trick. It gives a character result because the
input x represents categories. It also reports all modes.
>
> Thanks in advance,
>
> Elena Moltchanova
> Elena MOLTCHANOVA
> IIASA
> International Institute for Applied Systems Analysis
> A-2361 Laxenburg, Austria
> E-Mail: moltchan at iiasa.ac.at
> Phone : +43 2236 807-0
> Fax : +43 2236 71313
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list