[R] add diagonal to matrix

Martin Batholdy batholdy at googlemail.com
Sat Aug 3 20:54:56 CEST 2013


Hi,

I have a 5 columns x 4 rows matrix and would like to add a diagonal of zeros so that I end up with a 5x5 matrix.

x <- matrix(1:20, 4,5)


what is the easiest way to accomplish this in R?


thanks for any suggestions!


More information about the R-help mailing list