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
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
>
>
?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
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
__
4 matches
Mail list logo