Beno?t L?t? wrote:
> Hello,
>
> I have an elementary question (for which I couldn't find the answer on the
> web or the help): how can I extract the mode (modal score) of a vector?

Assuming that your vector contains only integers:

 > v <- sample(1:5, size=20, replace=T)
 > v
  [1] 1 1 1 1 2 3 5 1 1 5 2 4 1 3 1 1 5 4 1 5
 > vt <- table(v)
 > as.numeric(names(vt[vt == max(vt)]))
[1] 1
 >

Cheers,
Gad

#----------------------------
or more succinctly,

> names(vt[which.max(vt)])
[1] "1"

John

______________________________________________
R-help@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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to