[R] Can package plyr also calculate the mode?

Sarah Goslee sarah.goslee at gmail.com
Wed Apr 3 23:59:27 CEST 2013


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.

all1 <- ddply(all,"ACT_NAME", summarise, mean=mean(COUNTS), sd=sd(COUNTS),
>>>          q25=quantile(COUNTS,.25),median=quantile(COUNTS,.50),
>>> q75=quantile(COUNTS,.75),
>>>               q90=quantile(COUNTS,.90), q95=quantile(COUNTS,.95),
>>> q99=quantile(COUNTS,.99) )



On Wed, Apr 3, 2013 at 5:36 PM, Mossadegh, Ramine N.
<Ramine.Mossadegh at finra.org> wrote:
> So you mean it cannot be calculated within plyer?
>
> -----Original Message-----
> From: Sarah Goslee [mailto:sarah.goslee at gmail.com]
> Sent: Wednesday, April 03, 2013 5:36 PM
> To: Mossadegh, Ramine N.; r-help
> Subject: Re: [R] Can package plyr also calculate the mode?
>
> If you type
> ?mode
> at an R prompt you will be able to read the help for the mode() function.
>
> On Wed, Apr 3, 2013 at 5:34 PM, Mossadegh, Ramine N.
> <Ramine.Mossadegh at finra.org> wrote:
>> I tried mode=?mode(COUNTS) but that doesn't work.
>>
>> -----Original Message-----
>> From: Sarah Goslee [mailto:sarah.goslee at gmail.com]
>> Sent: Wednesday, April 03, 2013 5:32 PM
>> To: Mossadegh, Ramine N.
>> Cc: r-help
>> Subject: Re: [R] Can package plyr also calculate the mode?
>>
>> Sure, you can add the mode in, following the format by the other summary statistics.
>>
>> ?mode
>>
>> Sarah
>>
>> On Wed, Apr 3, 2013 at 5:25 PM, ramoss <ramine.mossadegh at finra.org> wrote:
>>> I am trying to replicate the SAS proc univariate in R.  I got most of
>>> the stats I needed for a by grouping in a data frame using:
>>>
>>> all1 <- ddply(all,"ACT_NAME", summarise, mean=mean(COUNTS), sd=sd(COUNTS),
>>>          q25=quantile(COUNTS,.25),median=quantile(COUNTS,.50),
>>> q75=quantile(COUNTS,.75),
>>>               q90=quantile(COUNTS,.90), q95=quantile(COUNTS,.95),
>>> q99=quantile(COUNTS,.99) )
>>> So I got the mean, median std dev, quantiles etc.
>>>
>>> IS there any way I can add the mode to the mixt. Thanks ahead for any
>>> suggestions.
>>>
>>>
>>>

--
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list