# How to take many samples of 10 from a large list, without replacement overall

I've got a large set of data (20,000 data points), from which I want to take repeated samples of 10 data points. However, once I've picked those 10 data points, I want them to not be picked again.

I've tried using the sample function, but it doesn't seem to have an option to sample without replacement over multiple calls of the function. Is there a simple way to do this?

-

You could call sample once on the entire data set to permute it. Then when you want to get a sample you could grab the first 10. If you want another sample grab the next 10. So on and so forth.

-

Dason's thought, implemented in R:

sample <- split(sample(datapoints), rep(1:(length(datapoints)/10+1), each=10))
sample[[13]] # the thirteenth sample

-
 (+1) Really neat R code. Of note, it will not work if $n$ is odd. – chl♦ Oct 31 '10 at 22:24 @chl Thanks! But I think it will work. The task was to give samples of size 10 from a set of datapoints. Assume n = length(datapoints). The code gives the maximum number (n %/% 10) of such samples. The first corner case is n<10 (anyway ruled out in the problem statement by describing the dataset as 'large', i.e. n>10). In that case you get the datapoints back and a warning (not an error). The second corner case is if there are dangling elements (when n %% 10 != 0). Then you get as many samples as possible and a warning (not an error). Odd n situations are subsumed in one of these two cases. – conjugateprior Nov 1 '10 at 8:44 It seems the first element of the list is of length 11, not 10, and sum(unlist(lapply(sample, length))) return the length of datapoints (which I set to 1001). – chl♦ Nov 1 '10 at 9:05 @chl Damn! You're quite right. – conjugateprior Nov 1 '10 at 9:37

This should work:

x <- rnorm(20000)
x.copy <- x
samples <- list()
i <- 1
while (length(x) >= 10){
tmp <- sample(x, 10)
samples[[i]] <- tmp
i <- i+1
x <- x[-match(tmp, x)]
}

table(unlist(samples) %in% x.copy)


However, I don't think that's the most elegant solution...

-