[R] How to get mode in case of discrete or categorial data
John Fox
jfox at mcmaster.ca
Fri Nov 12 14:52:39 CET 2004
Dear Vito,
How about names(t)[t == max(t)], which will pick up multiple modes if
there's a tie. By the way, I recall a discussion of this question on r-help
not too long ago.
I hope this helps,
John
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Vito Ricci
> Sent: Friday, November 12, 2004 8:21 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] How to get mode in case of discrete or categorial data
>
> Dear all,
>
> in a previuos message was asked how get the mode of
> continous distribution. Now I'm asking if there an R function
> to obtain the mode in case of a discrete distribution or
> categorial data. The only way is to use table():
>
> > x<-rep(1:5,100)
> > s<-sample(x,40)
> > t<-table(s)
> > t
> s
> 1 2 3 4 5
> 13 10 5 4 8
>
> the mode is value=1
>
> Thanks
> Cordially
> Vito
>
More information about the R-help
mailing list