[R] How to get the most frequent value of the subgroup

David Winsemius dwinsemius at comcast.net
Thu Mar 29 17:11:16 CEST 2012

On Mar 29, 2012, at 9:30 AM, Jung, Yongsuhk wrote:

> Dear Members of the R-Help,
> While using a R function - 'aggregate' that you developed, I become  
> to have a question.
> In that function,
>> aggregate(x, by, FUN, ..., simplify = TRUE)
> I was wondering about what type of FUN I should write if I want to  
> get "the most frequent value of the subgroup" as a summary  
> statistics of the subgroups.

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.)

> 	[[alternative HTML version deleted]]


David Winsemius, MD
West Hartford, CT

More information about the R-help mailing list