Skip to content
Prev 125846 / 398500 Next

Calculating group means using self-written function

Hi

lauri.nikkinen at gmail.com napsal dne 02.10.2007 13:19:09:
vsid$lev=vsid$date)

Shall be

aggregate(vsid$lev, list(vsid$month, vsid$yeari), fun, y=vsid$date)
## S3 method for class 'data.frame':
aggregate(x, by, FUN, ...)

...
further arguments passed to or used by methods.

Your function has 2 arguments one is x which is assigned vsid$lev and the 
other is y which you want to assign vsid$date. You can imagine that 
aggregate splits your "x" according to the levels mentioned in "by" and 
applies to each split a function "fun" together with any other argument, 
in your case "y". So you need to provide a correct name to your function 
otherwise it does not know what to do.

Regards
Petr
...