'rle' is also your friend:

>  x = c(1,2, 4,4,4,4, 5,5,5,6,6,5,5,5,5,5,6,6,6,13, 17,17,30,100,300)
>
> barplot(table(x))
> rle(x)
Run Length Encoding
  lengths: int [1:12] 1 1 4 3 2 5 3 1 2 1 ...
  values : num [1:12] 1 2 4 5 6 5 6 13 17 30 ...
> y <- rle(x)
> y$values[which.max(y$lengths)]
[1] 5
>


On Sun, Jan 8, 2012 at 9:37 AM, andrija djurovic <djandr...@gmail.com> wrote:
> Hi. You can do something like this:
> #find the most frequent values of x
>> t <- table(x)
>> t[t==max(t)]
> 5
> 8
> #sort table t based on frequencies
>> t[order(as.numeric(t),decreasing = TRUE)]
> x
>  5   6   4  17   1   2  13  30 100 300
>  8   5   4   2   1   1   1   1   1   1
> #extract any range from sorted table
>> t[order(as.numeric(t),decreasing = TRUE)][1:3]
> x
> 5 6 4
> 8 5 4
>
> I hope this helps.
>
> Andrija
>
>
> On Sun, Jan 8, 2012 at 1:48 PM, Mary Kindall <mary.kind...@gmail.com> wrote:
>> In a frequency distribution table (bell shaped), how can we find the most
>> frequent range?
>> for example:
>>
>>  x = c(1,2, 4,4,4,4, 5,5,5,6,6,5,5,5,5,5,6,6,6,13, 17,17,30,100,300)
>>
>> barplot(table(x))
>>
>>
>> In the code above, which function do we use to find that the most
>> frequent value range from 4 to 6.
>>
>> Thanks.
>>
>>
>>
>> --
>> -------------
>> Mary Kindall
>> Yorktown Heights, NY
>> USA
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@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.
>
> ______________________________________________
> R-help@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.



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

______________________________________________
R-help@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.

Reply via email to