set.seed(seed)
Set the seed of R‘s random number generator, which is useful for creating simulations or random objects that can be reproduced.
seed – A number.
Example. Create simulated values that are reproducible.
> set.seed(5)
> rnorm(5)
[1] -0.84085548 1.38435934 -1.25549186 0.07014277 1.71144087
> set.seed(5)
> rnorm(5)
[1] -0.84085548 1.38435934 -1.25549186 0.07014277 1.71144087
The seed number you choose is the starting point used in the generation of a sequence of random numbers, which is why (provided you use the same pseudo-random number generator) you'll obtain the same results given the same seed number.