Skip to content
Back to formatted view

Raw Message

Message-ID: <20080906183739.GA7140@psych.upenn.edu>
Date: 2008-09-06T18:37:39Z
From: Jonathan Baron
Subject: Mode value
In-Reply-To: <3aaf1a030809061108x8a9cebaj46d06af1606f099c@mail.gmail.com> <c502a9e10809061102s33f6ae3dw8bd2aafbecc5e22@mail.gmail.com> <291439.40978.qm@web25608.mail.ukl.yahoo.com>

On 09/06/08 17:24, Carlos Morales wrote:
> Hello everyone,
> 
> 
> I would like to know if there is any function to calculate the mode value, or I have 
> to build one to do it.

I just did this the other day.  Funny you should ask.  It finds the
mode of each row of a matrix called Pbest.

Pbest.p <- apply(Pbest,1,function(x) 
 x[which.max(as.vector(table(x)))][1])

So to get the mode of a vector v1, the following should work (but I
haven't tried it):

v1[which.max(as.vector(table(v1)))][1]

-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron