randomSample(x, size = numRows(x), prob = NULL, full.partition = "none")
n
(the number of observations in
x
).
n
, giving selection probabilities.
If the elements of prob do not sum to one, they are normalized.
The default
NULL
indicates equal probabilities.
"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.
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
.
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))