What is the canonical way to sum a 3D array along dimension 3 (thereby yielding a matrix)?
I know I can apply(A,c(1,2),sum)
but (wrongly or rightly) I got the impression from somewhere that using apply
is no better than using for
loops.
I could probably aperm
the array, colSum
it, then unaperm
it again, but that wouldn't be very readable.
Is there a better way?