Re: [R] Summing up diagonals w/o for-loop

2008-02-26 Thread Marc Schwartz
Camarda, Carlo Giovanni wrote: > Dear R-users, > > is there any way to sum up the elements of the "diagonals" of a matrix > without using a for-loop? While there is a simple way over rows and > columns, I don't see a straightforward multiplication for the diagonals, > am I too demanding? Or, more l

Re: [R] Summing up diagonals w/o for-loop

2008-02-26 Thread Greg Snow
Does this do what you want? > d <- col(mat) - row(mat) > tapply( mat, d, sum ) Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECT