[R] Another loop - deloop question
Talbot Katz
topkatz at msn.com
Fri Feb 2 21:03:32 CET 2007
Hi.
You folks are so clever, I thought perhaps you could help me make another
procedure more efficient.
Right now I have the following setup:
p is a vector of length m
g is a list of length n, g[[i]] is a vector whose elements are indices of p,
i.e., integers between 1 and m inclusive); the g[[i]] cover the full set
1:m, but they don't have to constitute an exact partition, theycan overlap
members.
y is another list of length n, each y[[i]] is a vector of the same length as
g[[i]].
Now I build up the vector p as follows:
p=rep(0,m)
for(i in 1:n){p[g[[i]]]=p[g[[i]]]+y[[i]]}
Can this loop be vectorized?
Thanks!
-- TMK --
212-460-5430 home
917-656-5351 cell
More information about the R-help
mailing list