How to set seed for random sample selection?

718 views Asked by At

Based on a data frame with grouped samples I'd like to pick 5 samples randomly from each group. I can do so easily using the function stratified from package splitstackshape. But is it possible to set a seed as to make the selection reproducible?

data(iris)
library(splitstackshape)
stratified(iris, "Species", 5)
1

There are 1 answers

0
pieterbons On BEST ANSWER

You can add the code set.seed(1) before evaluating the stratified() command. This makes sure the random numbers are generated from the same starting point making them reproducible.