Random sample without replacement

DESCRIPTION:

Generates a Simple Random Sample (SRS) from a vector, matrix, or data frame.

USAGE:

randomSample(x, size = numRows(x), prob = NULL, full.partition = "none") 

REQUIRED ARGUMENTS:

x
vector, matrix, or dataframe.

OPTIONAL ARGUMENTS:

size
integer, size of the sample. Default is n (the number of observations in x).
prob
vector of probabilities of length n, giving selection probabilities. If the elements of prob do not sum to one, they are normalized. The default NULL indicates equal probabilities.
full.partition
character, one of "first", "last", or "none"; Return the initial (if "first") or final (if "last") size elements of a full sample of size n. If "none", do not generate a full sample. Valid only if size < n; ignored otherwise. See for details.

DETAILS:

This uses balancedSample to sample indices, then subscripts the corresponding observations from x. The result is similar conceptually to sample(x, size, prob), except that this samples rows of matrices, uses a faster sampling algorithm, and samples with unequal probabilities correctly.

If size>n, or size*max(prob)>1, then sampling is done with "minimal replacement"; see balancedSample.

SEE ALSO:

, .

EXAMPLES:

randomSample(stack.loss, size=10) # 10 elements, without replacement 
randomSample(stack.loss)          # permutation of the original 21 elements 
randomSample(stack.loss, size=42) # each observation twice, random order 
randomSample(stack.loss, size=10, prob=c(1:21))