Skip to content
Prev 155218 / 398502 Next

Mode value

On 09/06/08 17:24, Carlos Morales wrote:
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]
Message-ID: <20080906183739.GA7140@psych.upenn.edu>
In-Reply-To: <3aaf1a030809061108x8a9cebaj46d06af1606f099c@mail.gmail.com> <c502a9e10809061102s33f6ae3dw8bd2aafbecc5e22@mail.gmail.com> <291439.40978.qm@web25608.mail.ukl.yahoo.com>