Re: [R] request: a class having max frequency

From: Chuck Cleland <ccleland_at_optonline.net>
Date: Fri, 06 Jun 2008 09:28:38 -0400

On 6/6/2008 9:18 AM, Chuck Cleland wrote:

> On 6/6/2008 9:14 AM, Muhammad Azam wrote:

>> Dear R users
>> I have a very basic question. I tried but could not find the
>> required result. using
>> dat <- pima
>> f <- table(dat[,9])
>>
>>> f
>> 0 1 500 268
>> i want to find that class say "0" having maximum frequency i.e 500. I
>> used
>>> which.max(f)
>> which provide 0 1 How can i get only the "0". Thanks and
> 
> table(iris$Species)
> 
>     setosa versicolor  virginica
>         50         50         50
> 
> which.max(table(iris$Species))
> setosa
>      1
> 
> names(which.max(table(iris$Species)))
> [1] "setosa"

   If, as above, more than one category frequency is at the maximum, you might want something like this:

x <- table(iris$Species)

which(x == max(x))

     setosa versicolor  virginica
          1          2          3

names(which(x == max(x)))
[1] "setosa"     "versicolor" "virginica"

>> best regards
>>
>> Muhammad Azam Ph.D. Student Department of Medical Statistics,
>> Informatics and Health Economics University of Innsbruck, Austria
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 06 Jun 2008 - 16:38:37 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 06 Jun 2008 - 17:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive