-1

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)
erc
  • 10,113
  • 11
  • 57
  • 88
  • 3
    Yes, `set.seed(123);stratified(iris, "Species", 5)` gives the same output everytime. Are you looking for something else? – Ronak Shah Jul 14 '20 at 08:47
  • OK, yes, I tried that but didn't run set.seed() again before running stratified again! Makes sense, thanks! – erc Jul 14 '20 at 08:51

1 Answers1

1

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.

pieterbons
  • 1,604
  • 1
  • 11
  • 14