take_sample | R Documentation |
A set of methods to generate random samples from data frames and data simulations. For data frames, individual rows are sampled. For vectors, elements are sampled.
take_sample(x, n, replace = FALSE, ...)
## Default S3 method:
take_sample(
x,
n = length(x),
replace = FALSE,
prob = NULL,
.by = NULL,
groups = .by,
orig.ids = FALSE,
...
)
resample(..., replace = TRUE)
x |
The object from which to sample |
n |
Size of the sample. |
replace |
Logical flag: whether to sample with replacement. (default: |
prob |
Probabilities to use for sampling, one for each element of |
.by |
Variables to use to define groups for sampling, as in |
groups |
Variable indicating blocks to sample within |
orig.ids |
Logical. If |
... |
Arguments to pass along to specific sample methods. |
These are based in spirit on the sample functions in the {mosaic}
package,
but are redefined here to 1) avoid a dependency on {mosaic}
and 2) bring the arguments in
line with the .by =
features of {dplyr}
.
A vector or a data frame depending on the nature of the x
argument.
take_sample(sim_03, n=5) # run a simulation
take_sample(Clock_auction, n = 3) # from a data frame
take_sample(1:6, n = 6) # sample from a vector
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.