rrandomsplitstackshape

How to set seed for random sample selection?


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)

Solution

  • 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.