Hi all,

source vector = (1,2)
the length of the target vector = 3
 
My expected "complete" output should be:
111, 112, 121, 122, 211, 212, 221, 222 (they are Not numerical numbers, they 
are equivalent to abc and aab etc.).

Not perfect solutions suggested by others so far: 
 
solution1: sample(c(1,2),3,replace=TRUE) just gives me one "randomly 
sampled" combination at a time. However, I need the whole list displayed 
above at a time.

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).

Thanks in advance.

Rui

______________________________________________
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to