I have an R script that systematically perform changes to a 3x3 matrix by scalar multiplication as follows
R <- matrix(rexp(9, rate=.1), ncol=3);
for (i in 1:360) {
K = i*R;
...
}
and use the modified matrix for further calculations within the loop. However, the loop itself is nested inside two other for loops, making the script very slow. So my question is, how can I vectorize this innermost loop such that the result instead is a three-dimensional array A of size 3x3x360 where
A[,,i] = i*R;
for all i ranging from 1 to 360?