Spencer
thank you!
just what I wanted. I have a feeling that jj3 is qualitatively different from the other two.
Nevertheless, I'm sure it'll crack sooner or later!
best wishes
rksh
At 07:34 am -0700 28/07/04, Spencer Graves wrote:
It's not obvious what pattern you want, but some variants of the following would work for jj1 and jj2:
1+outer(1:9, 1:9, "+")%%3
In particular the following are equal to your jj1 and jj2: jj1. <- 1+outer(0:8, rep(0:2, e=3), "+")%%3
jj2. <- 1+outer(0:8, c(1,2,1,3,1,3,2,3,2)-1, "+")%%3
I couldn't figure out jj3, but this system may not work so easily for that. hope this helps. spencer graves
Robin Hankin wrote:
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 [EMAIL PROTECTED] (edit in obvious way; spam precaution)
______________________________________________ [EMAIL PROTECTED] 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
