sample takes a sample of the specified size from the elements of
x either with or without replacement. Unlike base::sample,
sample handles data frames in a reasonable manner.
Usage
sample(x, size, replace = FALSE, prob = NULL)
Arguments
x
an integer, vector, or data frame.
size
a non-negative integer giving the number of items to choose.
replace
logical indicating whether sampling should be performed with or without
replacement.
prob
a vector of probability weights for obtaining the elements
of the vector being sampled.
Value
If x is a vector, a vector of length size
with elements drawn from x.
If x is a integer, a vector of length size
with elements drawn from 1:x.
If x is a data frame, a data frame with size rows, all the columns
in x and one additional column indicating the location of the selected
rows in x.