[R] make matrices as many as possible with a constraint

Kathryn Lord kathryn.lord2000 at gmail.com
Fri Dec 12 01:38:20 CET 2014


Dear R users,

I'd like to make 4 by 7 matrices as many as possible with natural numbers 1
through 28 such that each matrix have different elements of each column.

For example,

simply here is one

> a1 <- matrix(1:28, 4,7)
> a1
     [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    1    5    9   13   17   21   25
[2,]    2    6   10   14   18   22   26
[3,]    3    7   11   15   19   23   27
[4,]    4    8   12   16   20   24   28

another one

> a2 <- matrix(1:28, 4,7, byrow=T)
> a2
     [,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,]    1    2    3    4    5    6    7
[2,]    8    9   10   11   12   13   14
[3,]   15   16   17   18   19   20   21
[4,]   22   23   24   25   26   27   28

Matrices a1 and a2 have different columns, and I guess there are such many
matrices.

Any suggestion will be greatly appreciated.

Best,

Kathryn Lord

	[[alternative HTML version deleted]]



More information about the R-help mailing list