Skip to content

How to get the most frequent value of the subgroup

3 messages · Jung, Yongsuhk, R. Michael Weylandt, David Winsemius

#
What you are looking for is commonly called the mode, but
(surprisingly?) there doesn't seem to be a standard implementation for
mode() in R. (the mode function gives you something else entirely) --
this SO thread may be of help:
http://stackoverflow.com/questions/2547402/standard-library-function-in-r-for-finding-the-mode

Michael
On Thu, Mar 29, 2012 at 9:30 AM, Jung, Yongsuhk <yjung.phd at ivey.ca> wrote:
#
On Mar 29, 2012, at 9:30 AM, Jung, Yongsuhk wrote:

            
Something along the lines of

  function(x){  tbl <- table(x);  retrun(names(tbl)[which.max(tbl)] }

You could also search for definitions that have appeared over the  
years in rhelp for a mode function (but not the existing mode function  
which is not designed to deliver what you request.)