What your cumsumA calculates is
array(cumsum(as.numeric(A)),c(3,3,3))
is this what you were looking for?
_________________________________________
> 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
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu. To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message: unsubscribe s-news
>
|