[R] statistical mode function

Warnes, Gregory R gregory_r_warnes at groton.pfizer.com
Fri Aug 24 18:19:10 CEST 2001



> From: ben at zoo.ufl.edu [mailto:ben at zoo.ufl.edu]
>
[snip]
>   How about
> 
> mode1 <- function(x) {
>   t0 <- table(x)
>   as.numeric(names(t0)[t0==max(t0)])
> }
> 
> e.g.
>  mode1(rbinom(100,10,0.4))
> 
[snip]
>
>   If someone else can come up with a one-liner I'd be mildly 
> interested.
>

How about:

as.numeric(names(rev(sort(table(x))))[1])

-Greg


LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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