[R] need help on computing double summation

From: Kerry Bush <kerryrekky_at_yahoo.com>
Date: Thu 16 Jun 2005 - 01:40:58 EST


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?



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 16 01:46:28 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:42 EST