[R] newbie query: simple crosstabs

hadley wickham h.wickham at gmail.com
Wed Apr 8 00:14:52 CEST 2009


On Tue, Apr 7, 2009 at 4:41 PM, Jorge Ivan Velez
<jorgeivanvelez at gmail.com> wrote:
> Hi Eik,
> You're absolutely right. My bad.
>
> Here is the correction of the code I sent:
>
> apply(mydata[,-1], 2, tapply, mydata[,1], function(x) sum(x)/length(x))

Or more simply:

apply(mydata[,-1], 2, tapply, mydata[,1], mean)

Hadley

-- 
http://had.co.nz/




More information about the R-help mailing list