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? Thanks in advance for your help. [[alternative HTML version deleted]]
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 -- Gad Abraham Department of Mathematics and Statistics The University of Melbourne Parkville 3010, Victoria, Australia email: g.abraham at ms.unimelb.edu.au web: http://www.ms.unimelb.edu.au/~gabraham
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