[R] Summarizing levels for future commands
Suzanne E. Blatt
SuzieBlatt at netscape.net
Wed Apr 16 13:17:23 CEST 2003
Thanks to those who have been responding to my query.
I've done the following, and get the following results:
"elm.american" "hawthorn" "ironwood"
2 1 4
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,
>> samp = sample(1:10, 50, replace = TRUE)
> 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)]
>Hope this helps.
More information about the R-help