[R] Summing over an index of an array

Moshe Olshansky m_olshansky at yahoo.com
Wed Feb 20 22:39:07 CET 2008


Try

apply(A,2:3,sum)

--- Saurav Pathak <saurav at sas.upenn.edu> wrote:

> Hi,
> 
> I cannot seem to figure out how to sum over an index
> of a array.
> For example, let A be a 3 dimensional array.  I want
> to, say, find
> the sum over the first dimension.  That is
> 
>         S_jk = Sum_i A_ijk
> 
> where now S is a 2-dim matrix.  I dont want to use a
> loop.
> 
> Thanks,
> -- 
> saurav
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>



More information about the R-help mailing list