[R] tapply for function taking of >1 argument?
petr.pikal at precheza.cz
Wed Feb 3 10:16:19 CET 2010
r-help-bounces at r-project.org napsal dne 02.02.2010 22:16:06:
> 'fraid not :-((
> tapply( data, groups, weighted.mean, weights)
tapply(seq(along=lll), rrr, function(i, x, w) weighted.mean(x[i], w[i]),
If you want to subset more than one thing, subset the index vector.
The above help I obtained from Prof.Ripley several years ago so (untested)
tapply( seq(along=data), groups, function (i, x, w) weighted.mean(x[i],
w[i]), x=data, w=weights)
I believe it shall still work.
> won't work because the *entire* weights vector is passed as the 2nd arg
> weighted.means. But weighted.mean needs 'weights' to be split in the
> way as 'data' -- the first and 2nd args need to correspond.
> Jorge Ivan Velez wrote:
> > Hi sjaffem,
> > You were almost there:
> > tapply( yourdata, groups, weighted.mean, weights)
> > See ?tapply for more information.
> > HTH,
> > Jorge
> View this message in context:
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help