This is the "sample_n" from dplyr in R.
https://dplyr.tidyverse.org/reference/sample.html
For reproducibility, I should place a seed so that someone else can get my exact results.
Is there a built-in way to set the seed for "sample_n"? Is this something that I do in the environment and "sample_n" responds to it?
These are not built-into the "sample_n" function.
.
The dplyr::sample_n
documentation tells that :
This is a wrapper around sample.int() to make it easy to select random rows from a table. It currently only works for local tbls.
so behind sample_n
, sample.int
is called, which means that the standard Random Number Generator is used, and that you can use set.seed
for reproducibility.
Does this example help? In it, I am using set.seed
and the mtcars
dataset.
set.seed(1)
x <- mtcars
sample_n(x, 10)
sample_n(x, 10) #without set.seed()
set.seed(1)
x <- mtcars
sample_n(x, 10)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With