[R] calculations on diagonals of a matrix
gfeeney at gfeeney.com
Sat May 19 19:42:08 CEST 2001
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.,
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
More information about the R-help