[R] matrix problem

William Simpson william.a.simpson at gmail.com
Sat Jul 4 17:17:03 CEST 2009


Can anybody please tell me a good way to do the following?

Given a vector, number of rows and number of columns, return a matrix
as follows. Easiest to give an example:

x=c(1,2), nrow=5, ncol=4

return the matrix:

   1 0 0 0
   2 1 0 0
   0 2 1 0
   0 0 2 1
   0 0 0 2

Thanks very much for any help!
Bill




More information about the R-help mailing list