[R] how to convert a vector to an upper matrix

Zhishi Wang wzhishi at gmail.com
Fri Jun 10 07:15:05 CEST 2011


Hi all,

If I have a vector A<-1:6, I would like to convert A to an upper
matrix M=[0 1 2 3 ; 0 0 4 5 ; 0 0 0 6; 0 0 0 0].
That is, if the length of the known vector is n, then the order m of
the matrix I'd like to have should satisfy m(m-1)/2=n
How could I do this in R?
I really don't want to do it using a loop. Is there a function in R to do this ?

Thanks!

Best,
Zhishi



More information about the R-help mailing list