[R] help with tapply and weighted.mean

Kosenkov Kirill Kosenkov.Kirill at nac.spb.ru
Thu Jul 31 20:00:13 CEST 2003


Hello!

I have data frame with 'weights' in one of the columns. I need to 
compute weighted mean on another column other factor variable and 
i am trying to:

res<-tapply(data$k,list(data$model),weighted.mean,w=data$w,na.rm=T)

and i get:

Warning messages:
1: longer object length
	is not a multiple of shorter object length in: x * w
2: longer object length
	is not a multiple of shorter object length in: x * w
3: longer object length
	is not a multiple of shorter object length in: x * w
4: longer object length
	is not a multiple of shorter object length in: x * w
5: longer object length
	is not a multiple of shorter object length in: x * w
6: longer object length
	is not a multiple of shorter object length in: x * w
7: longer object length
	is not a multiple of shorter object length in: x * w
8: longer object length
....

What i am doing wrong? How i can pass vector of weights to the 
'weighted.mean' when using 'tapply'?

Thanks!




More information about the R-help mailing list