[R] Can package plyr also calculate the mode?

Jim Lemon jim at bitwrit.com.au
Thu Apr 4 01:05:09 CEST 2013


On 04/04/2013 09:56 AM, Peter Ehlers wrote:
> On 2013-04-03 14:59, Sarah Goslee wrote:
>> Of course it can. Use the mode() in the same way you used the mean()
>> function.
>>
>> You didn't provide a reproducible example, so I can't provided tested
>> code, but I would think that you can add
>> mode=mode(COUNTS) to the ddply() arguments.
>
> ?mode will direct you to the help page for _storage_ mode of an object.
> That's not likely what the OP had in mind. It seems that what s/he
> wants is the "most frequent value". This is (usually) a pretty useless
> piece of information, but there are a number of packages that do
> provide it.
>
> To the OP:
> Install package sos and then do findFn("mode") to see what's available.
> E.g. packages, pracma, asbio, dprep, rattle and many others.
> Do note that they handle the multimodal situation differently.
>
> Or, write your own, perhaps using table() and which.max().
>
The OP might find the Mode (note capital M) function (prettyR) helpful.

Jim



More information about the R-help mailing list