[R] How to make a matrix of a number of factors?

2009-11-22 Thread Peng Yu
I use the following code to generate a matrix of factors. I'm wondering if there is a way to make it more general so that I can have any number of factors (not necessarily 5). a=3 b=4 c=5 d=6 e=7 A=1:a B=1:b C=1:c D=1:d E=1:e X=matrix(nr=a*b*c*d*e,nc=5) for(i_a in 1:a-1) { for(i_b in 1:b-1)

Re: [R] How to make a matrix of a number of factors?

2009-11-22 Thread baptiste auguie
Hi, Try this, do.call(expand.grid, lapply(7:3, seq, from=1)) HTH, baptiste 2009/11/22 Peng Yu pengyu...@gmail.com: I use the following code to generate a matrix of factors. I'm wondering if there is a way to make it more general so that I can have any number of factors (not necessarily