Re: [R] Matrix from a vector?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu 21 Sep 2006 - 23:07:48 GMT

Try this:

matrix(rhset[outer(1:8, 1:8, "-") %% 8 + 1], 8)

On 9/21/06, kone <attenka@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@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.
>



R-help@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. Received on Fri Sep 22 09:10:53 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 22 Sep 2006 - 01:30:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.