[R] "mode" function

Dejian Zhao zhaodj at ioz.ac.cn
Wed Sep 1 04:48:47 CEST 2010


 R does have a mode function, but it seems NOT to do the same thing as in 
matlab.

 > A <- matrix(c(1:3,1,3,2,3,3,2),nrow=3,byrow=F)
 > A
      [,1] [,2] [,3]
[1,]    1    1    3
[2,]    2    3    3
[3,]    3    2    2
 > A[,2]
[1] 1 3 2
 > mode(A)
[1] "numeric"
 > mode(A[,2])
[1] "numeric"


On 2010-9-1 5:19, Iain Martyn wrote:
> Hi, I have what I think is a simple question/issue but I have unable to find the answer for it either in the R-manual or by browsing the web.
>
>
>
> I would like to know if there is a "mode" function in R, such that from a vector or matrix the function returns the most common value.  In other programs I use (such as Matlab) I can have for exampe a 3X3 matrix A, A=[1 2 3; 1 3 2; 3 3 2] and I can find the mode of the rows so that mode(A[1:3,:]) returns a 1X3 matrix [1 3 2].
>
> Is this possible in R as well?  If not, how would one go about this?
>
> Thank you very much,
>
> Bill
>   		 	   		
> 	[[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.
>



More information about the R-help mailing list