[R] How sample without replacement on more than one variables?

Erik Iverson eriki at ccbr.umn.edu
Sun May 23 09:33:23 CEST 2010

thmsfuller066 at gmail.com wrote:
> Hello All,
> sample() only sample on one variable x. But I'm interested in sampling
> more than one variable without replacement.
> Suppose I have 3 vectors x, y, z. I want to draw samples from all
> three vectors such that the combination of the three elements in each
> draw is not the same as any previous draws. I could use expand.grid to
> generate a vector out of the three vectors. But when the number of
> vectors are large and the number of elements in some vectors are
> large, it will be infeasible to do so.
> If you know there is a method on sampling on more than one variables,
> would you please let me know? Thank you!

Can you give a reproducible example?  Since you suggested the method that is 
most reasonable, but it will not work in large cases, I suppose you'll have to 
draw independently from each vector one at a time, then somehow concatenate the 
results, perhaps as a character vector, even if the vectors are, say, integers. 
  Then repeat this process checking each time if your new vector is %in% the 

There may be a much better way, too, see if anyone else responds.

Also, you'll have to think about what a unique sample is.


x <- 1:3

y <- 2:4 ,

is x = 2, y = 3 the same as x = 3, y = 2?

Good luck,

More information about the R-help mailing list