[R] cumsum in 3d arrays

David Winsemius dwinsemius at comcast.net
Sat Nov 26 17:24:05 CET 2011


On Nov 26, 2011, at 9:32 AM, zloncaric wrote:

> Hello!
>
> Is it posible to apply /cumsum()/ along the 3rd dimension of 3D array?
> Something like matrlab function - /cumsum (*A*,dim)/ which returns the
> cumulative sum of the elements along the dimension of *A* specified by
> scalar dim.
>

`apply` lets you chose which dimension gets selected.

Perhaps:

apply(mat, 3, cumsum)

(This is pretty basic stuff so you should probably be reading or at  
least skimming somewhat more thoroughly than you have so far the  
Introduction to R document and there is also the R for Matlab document  
by Bob Muenchen ... and a compendium of equivalencies by Hiebeler at: www.math.umaine.edu/~hiebeler/comp/matlabR.html 
  )

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list