[R] most frequent value

Jim Lemon drjimlemon at gmail.com
Mon Jun 15 01:35:05 CEST 2015


Hi Ragia,
The basic method is to use "table" and examine the result:

> a<-matrix(c(3,3,4,3,6,6),nrow=2)
> b<-matrix(c(3,3,4,4,6,6),nrow=2)
> table(a)
a
3 4 6
3 1 2

but you can get the modal value directly like this:

library(prettyR)
Mode(a)
[1] "3"
Mode(b)
[1] ">1 mode"

Jim

On Mon, Jun 15, 2015 at 9:04 AM, Ragia Ibrahim <ragia11 at hotmail.com> wrote:
> Dear group,
> I have the following integer object
>
>> a
>
> 3 4 6
> 3 3 6
>
> how to get the most frequent value (it should be 3)
>
> and get nothing if no frequent one and all is equal
>
> 3 4 6
> 3 4 6
> Thanks in advance
> Ragia
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list