[R] elegant matrix creation

From: Robin Hankin <rksh_at_soc.soton.ac.uk>
Date: Wed 28 Jul 2004 - 23:25:53 EST


Hello everybody.

I am trying to reproduce a particular matrix in an elegant way. If I have

jj1 <-

structure(c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,
3,1,2,3,1,2,3,1,2,3,2,3,1,2,3,1,2,3,1,2,3,
1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,3,1,2,3,1,
2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,
2),.Dim = as.integer(c(9,9)))

[ image(jj1) is good here ] then I can get this with

kronecker(matrix(1,3,1),kronecker(1+outer(0:2,0:2,"+")%%3,matrix(1,1,3)))

I want to reproduce the following matrices in an equivalent way:

jj2 <- matrix(c(1,2,3,1,2,3,1,2,3,2,3,1,2,3,1,2,3,1,
1,2,3,1,2,3,1,2,3,3,1,2,3,1,2,3,1,2,1,2,3,1,2,
3,1,2,3,3,1,2,3,1,2,3,1,2,2,3,1,2,3,1,2,3,1,3,
1,2,3,1,2,3,1,2,2,3,1,2,3,1,2,3,1),9,9)

jj3 <- structure(c(1,2,3,2,3,1,3,1,2,1,2,1,2,3,2,3,1,

3,1,3,1,2,1,2,3,2,3,2,3,1,3,1,2,1,2,3,2,3,
2,3,1,3,1,2,1,2,1,2,3,2,3,1,3,1,3,1,2,1,2,
3,2,3,1,3,1,3,1,2,1,2,3,2,3,2,3,1,3,1,2,1, 2),.Dim =
as.integer(c(9,9)))

[ note that jj1-jj3 each have precisely 3 occurrences of A, B, and C
along each row, column and (broken) diagonal ].

Can anyone give me a nice elegant way of creating jj2 and jj3 please?

-- 
Robin Hankin
Uncertainty Analyst
Southampton Oceanography Centre
SO14 3ZH
tel +44(0)23-8059-7743
initialDOTsurname@soc.soton.ac.uk (edit in obvious way; spam precaution)
	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Jul 28 23:37:01 2004

This archive was generated by hypermail 2.1.8 : Fri 18 Mar 2005 - 02:40:28 EST