Re: [R] Summing over an index of an array

2008-02-20 Thread Gavin Simpson
On Wed, 2008-02-20 at 13:39 -0800, Moshe Olshansky wrote: > Try > > apply(A,2:3,sum) If speed is an issue, then colSums is a faster version of the above: > A <- array(c(1:27), dim = c(3,3,3)) > (res1 <- apply(A, 2:3, sum)) [,1] [,2] [,3] [1,]6 33 60 [2,] 15 42 69 [3,] 24 5

Re: [R] Summing over an index of an array

2008-02-20 Thread Moshe Olshansky
Try apply(A,2:3,sum) --- Saurav Pathak <[EMAIL PROTECTED]> 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 > >

Re: [R] Summing over an index of an array

2008-02-19 Thread Benilton Carvalho
?colSums On Feb 19, 2008, at 6:39 PM, Saurav Pathak 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 matr

[R] Summing over an index of an array

2008-02-19 Thread Saurav Pathak
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 __