[R] tapply and weighted means

Florent Bresson f_bresson at yahoo.fr
Thu Jan 12 15:44:06 CET 2006


I' m trying to compute weighted mean on different
groups but it only returns NA. If I use the following
data.frame truc:

x  y  w
1  1  1
1  2  2
1  3  1
1  4  2
0  2  1
0  3  2
0  4  1
0  5  1

where x is a factor, and then use the command :

tapply(truc$y,list(truc$x),wtd.mean, weights=truc$w)

I just get NA. What's the problem ? What can I do ?




More information about the R-help mailing list