[R] Matrix from a vector?

kone attenka at utu.fi
Thu Sep 21 21:30:59 CEST 2006


Hi,

Is there some function, which generates this kind of n x n -matrix  
from a vector?

 > rhset
[1]  1792   256 13312   512  1024  2048  8192  4096
 > 	m=matrix(nrow=length(rhset),ncol=length(rhset))
 > 	for(i in 1:length(rhset))
+ 	{
+ 		m[,i]=rhset
+ 		rhset=c(rhset[length(rhset)], rhset[2:length(rhset)-1])
+ 	}
 > m
       [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]
[1,]  1792  4096  8192  2048  1024   512 13312   256
[2,]   256  1792  4096  8192  2048  1024   512 13312
[3,] 13312   256  1792  4096  8192  2048  1024   512
[4,]   512 13312   256  1792  4096  8192  2048  1024
[5,]  1024   512 13312   256  1792  4096  8192  2048
[6,]  2048  1024   512 13312   256  1792  4096  8192
[7,]  8192  2048  1024   512 13312   256  1792  4096
[8,]  4096  8192  2048  1024   512 13312   256  1792


Atte Tenkanen
University of Turku, Finland



More information about the R-help mailing list