[R] Mode in case of discrete or categorial data
John Fox
jfox at mcmaster.ca
Fri Nov 12 17:32:54 CET 2004
Dear Thomas,
I believe that which.max() will report only the first maximum in case of
ties [which is why I suggested the more awkward t == max(t)].
Regards,
John
--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox
--------------------------------
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Thomas Lumley
> Sent: Friday, November 12, 2004 10:44 AM
> To: Vito Ricci
> Cc: r-help at stat.math.ethz.ch
> Subject: Re: [R] Mode in case of discrete or categorial data
>
> On Fri, 12 Nov 2004, Vito Ricci wrote:
> > Mode<-function(x){t<-table(x)
> > if (is.numeric(x)) as.numeric(names(t)[t == max(t)]) else
> (names(t)[t
> > == max(t)]) }
> >
> > Any other improvement and suggestion will welcome.
> >
>
> which.max is design for finding the maximum, so
> names(t)[which.max(t)]
>
>
> -thomas
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list