Dear S-News readers,
I'm working with 3D array objects created via tapply(), eg., tapply(vec,
list(x,y,z), sum). Using the returned array object, I want to create an
object that is the cumulative sum along the z dimension of the matrices
formed by x and y. So far, the best idea I've come up with is something
like the following, which involves a loop:
A <- array( rep(1:9, 3), c(3,3,3)) # test data array
cumsumA <- array(dim= dim(A)) # empty data array
for(z in 1:dim(A)[3]){cumsumA[,, z] <- apply(A[,, 1:z], c(1,2), sum)}
I suspect, however, that there is a better, more efficient way to do
this. Any suggestions?
Thanks for the help and advice.
-Paul
|