Here we show how to set seeds in R using the set.seed()
function, in order to be able to reproduce outputs.
When R outputs are random or based on simulations, by setting seeds, we can reproduce the same results as often as we want.
The set.seed()
function is from the "base" package.
To be able to reproduce a simulation or a random sample we can do the following (for example, using a normal distribution sampling).
[1] -0.56047565 -0.23017749 1.55870831 0.07050839 0.12928774
We can enter the same seed as often as we want and the same result will be produced.
[1] -0.56047565 -0.23017749 1.55870831 0.07050839 0.12928774
We can replicate multiple sampling too, provided the order of randomization does not change.
[1] -0.44577826 -1.20585657 0.04112631 0.63938841
[1] -0.78655436 -0.38548930 -0.47586788 0.71975069 -0.01850562 -1.37311776
The same can be replicated provided we have
rnorm(4, 0, 1)
as the first randomization followed by
rnorm(6, 0, 1)
after setting the same seed.
[1] -0.44577826 -1.20585657 0.04112631 0.63938841
[1] -0.78655436 -0.38548930 -0.47586788 0.71975069 -0.01850562 -1.37311776
The feedback form is a Google form but it does not collect any personal information.
Please click on the link below to go to the Google form.
Thank You!
Go to Feedback Form
Copyright © 2020 - 2024. All Rights Reserved by Stats Codes