Let's say 

 x <- c("eml.american", "hawthorn", "ironwood")
x <- rep(x, c(2, 1, 4))
y <- table(x)
names(y)[match(max(y), y)]






SuzieBlatt@netscape.net (Suzanne E. Blatt)
Sent by: r-help-bounces@stat.math.ethz.ch
04/16/2003 07:17 AM

 
        To:     bates@stat.wisc.edu (Douglas Bates)
        cc:     r-help@r-project.org
        Subject:        Re: [R] Summarizing levels for future commands



Hello,

Thanks to those who have been responding to my query.

I've done the following, and get the following results:

table(x)

"elm.american" "hawthorn" "ironwood"
2                1        4

which.max(table(x))

"3"

The first 'table' is fine, the 'which.max' part not.  Can I get it to 
actually use "ironwood", or is numeric all I can hope for?  I tried 
putting 'as.character' in front of the 'which.max' command but that didn't 
work.  The 'names(tbl)[match(max(tbl), tbl)]' also didn't work for me, 
claims it didn't know what the 'names' function was.

Any further suggestions most welcome,

Suzanne


>> samp = sample(1:10, 50, replace = TRUE)
>> table(samp)
>samp
> 1  2  3  4  5  6  7  8  9 10
> 5  3  7  3  4  2  8  9  3  6
>
>the most popular value is 8.
>
>As you can see, the table function tells you the frequencies of the
>values.  From that it is just a matter of extracting the index of the
>value with the maximum count and getting the label.
>
>> names(tbl)[match(max(tbl), tbl)]
>[1] "8"
>
>Hope this helps.
>

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



	[[alternate HTML version deleted]]

