# [R] calculations on diagonals of a matrix

Martin Henry H. Stevens hstevens at rci.rutgers.edu
Mon May 21 14:49:52 CEST 2001

```----- Original Message -----
From: "Griffith Feeney" <gfeeney at gfeeney.com>
> Given an nxm matrix A I want to compute the nxm matrix B whose ij-th
> element is the sum of the elements of A lying on the diagonal that ends
> with element ij, i.e.,
>

How about sum( diag(  A )[ 1:i ] )?

>      b_ij = a_ij + a_(i-1)(j-1) + a_(i-2)(j-2) + ...
>
> In APL (which I no longer use), I would use the 'rotate' operator to
derive
> an array whose columns are diagonals of the given array and then cumulate
> down columns. Is there a similar operator in R, or is there another/better
way?
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
-.-.-
> r-help mailing list -- Read
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
>
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
>

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```