View source: R/reproducibleSample.R
| reproducibleSample | R Documentation |
This function calls sample and stores the values that are
required to reproduce the exact same sampling in the attribute
random_seed of the returned vector. When this attribute is passed
to another call of this function, the values returned will be the same as
in the first call.
reproducibleSample(..., FUN = sample, random_seed = NULL)
... |
arguments passed to |
FUN |
the sample function to be called. Default: |
random_seed |
vector of integer as stored in |
This function returns what sample returns with an
attribute random_seed attached.
# Take a sample
x <- reproducibleSample(1:100, 10)
x
# The full seed vector is returned in the attribute "random_seed"
random_seed <- attr(x, "random_seed")
# Take a new sample, this time passing the seed vector
y <- reproducibleSample(1:100, 10, random_seed = random_seed)
y
# The values are identical to the values of the first sampling
identical(x, y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.