[R] How to do this "combination"?

Gabor Grothendieck ggrothendieck at myway.com
Thu Sep 9 06:24:57 CEST 2004


 <wanr <at> ucalgary.ca> writes:

: source vector = (1,2)
: the length of the target vector = 3
:  
: solution2: as.matrix(expand.grid(1:2, 1:2, 1:2)) almost implements what I 
: need. 
: 
: However, in my case, the length of the target vector is not fixed in 
: advance. For example, the output might be 11111, 11112, and etc coming from 
: the source vector (1,2).

If the only problem with that solution is that the length is not a parameter
then you could use this variation of it:

   as.matrix(do.call("expand.grid", rep(list(1:2),3)))




More information about the R-help mailing list