I need to execute foreach with two iteration variables of the same size (for example 1:n), but the function changes them in parallel as written here:
We call a and b the iteration variables, since those are the variables that are changing during the multiple executions. Note that we are iterating over them in parallel, that is, they are both changing at the same time.
What I need is to make foreach to change them independently, so that I would have a list with length n^2, not n.
example:
X = foreach(i=1:n, j=1:n) %do% (sum(M[i,]*M[j,]))
in the end I get a vector of length n which is only a diagonal of matrix X, not the full matrix.
P.S. I was trying to make this with for looping, but the computation time was too great to leave the code unoptimized.