[R] how calculate mean for each group

Marc Schwartz MSchwartz at medanalytics.com
Thu Oct 2 17:41:34 CEST 2003


On Thu, 2003-10-02 at 10:11, Simon Fear wrote:
> A little more succinctly and I hope also helpful:
> 
> > with(df, aggregate(list(mean=treatment),
>       list(group = group, duplicate = duplicate), mean))
> 
> Note that the name of the summary of treatment is likely
> best to be different from the name of the treatment
> variable itself. It is tempting to do something fancy picking
> up the name of the called function automatically, but
> I mostly use an unnamed summary function (x) { ...}, so I won't
> bother.
> 
> (BTW did I ever mention here how much I prefer with() to 
> attach()/forget.to.detach() ?)


LOL...

I supposed that this might be the time to raise the possibility of an
"Obfuscated R" contest?  ;-)

Thanks Simon.

Marc




More information about the R-help mailing list