[R] Matrix from a vector?
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Sep 22 01:07:48 CEST 2006
Try this:
matrix(rhset[outer(1:8, 1:8, "-") %% 8 + 1], 8)
On 9/21/06, kone <attenka at utu.fi> wrote:
> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list