[R] need help on computing double summation

Kerry Bush kerryrekky at yahoo.com
Wed Jun 15 17:40:58 CEST 2005


Dear helpers in this forum,

   This is a clarified version of my previous
questions  in this forum. I really need your generous
help on this issue.

> Suppose I have the following data set:
> 
> id x y 
> 023 1 2
> 023 2 5
> 023 4 6
> 023 5 7
> 412 2 5
> 412 3 4
> 412 4 6
> 412 7 9
> 220 5 7
> 220 4 8
> 220 9 8
> ......
> 

Now I want to compute the following double summation:

sum_{i=1}^k
sum_{j=1}^{n_i}(x_{ij}-mean(x_i))*(y_{ij}-mean(y_i))

i is from 1 to k,
indexing the ith subject id; and j is from 1 to n_i,
indexing the jth observation for the ith subject.

in the above expression, mean(x_i) is the mean of x
values for the ith
subject, mean(y_i) is the mean of y values for the ith
subject. 

Is there a simple way to do this in R?




More information about the R-help mailing list