[R] Large 3d array manipulation

Vemuri, Aparna avemuri at epri.com
Sat Feb 28 00:15:24 CET 2009

I have a large 3 dimensional array of size (243,246,768)
 The first dimension is Rows, second is columns and the third is Time. 

So for each row and column, I want to calculate the mean of time steps
1:8, 2:9, 3:10 and so on and assign the values to a new array. For this
I am using the following script.

for(i in 1:243)
for(j in 1:246)
for(k in 1:768)
newVar[i,j,k] <- mean( myVar[i,j,k:k+7])

This works, but needless to mention it take a very long time to loop
over all the rows, columns and time periods. I was wondering if there is
a simpler way to do this.


More information about the R-help mailing list