On Tue, 2 Feb 2010, sjaffe wrote:
'fraid not :-((
tapply( data, groups, weighted.mean, weights)
won't work because the *entire* weights vector is passed as the 2nd arg to
weighted.means. But weighted.mean needs 'weights' to be split in the same
way as 'data' -- the first and 2nd args need to correspond.
try
sapply( split( data.frame(x,w), grp) , do.call, what=weighted.mean )
HTH,
Chuck
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:
http://n4.nabble.com/tapply-for-function-taking-of-1-argument-tp1460392p1460419.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Charles C. Berry (858) 534-2098
Dept of Family/Preventive Medicine
E mailto:cbe...@tajo.ucsd.edu UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.