[R] Sampling from a population
Prof Brian Ripley
ripley at stats.ox.ac.uk
Tue Nov 20 10:05:08 CET 2001
On Tue, 20 Nov 2001, Andrew Criswell wrote:
> Hi ALL:
> Suppose you have a population of N <- 5 observations, x <- c(43, 28, 7, 61, 39). From that you can draw a maximum of 10 samples without replacement of size n <- 3. (Command choose(N,n) yields 10). For instance the samples I seek are
> 43, 61, 7
> 39, 7, 28 ...etc
> How can I get R to do that for me, to get an exhaustive list of samples of size n drawn without replacement from a population of size N? The command, sample(x, 3, replace=FALSE), works well for one draw. Is there a package that will handle multiple draws?
This is a question about drawing subsets, as covered in the Programmer's
Niche articles in Rnews. You want all subsets (not subvectors, as order
does not matter) of size n=3 from N=5 items.
There is some C code to so it in package lqs, where it is used for
exhaustive searching, but that doesn't currently have an R interface (it
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
More information about the R-help