- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why we should use set.seed in R?
The use of set.seed is to make sure that we get the same results for randomization. If we randomly select some observations for any task in R or in any statistical software it results in different values all the time and this happens because of randomization. If we want to keep the values that are produced at first random selection then we can do this by storing them in an object after randomization or we can fix the randomization procedure so that we get the same results all the time.
Randomization without set.seed
> sample(1:10)  4 10 5 3 1 6 9 2 8 7 > sample(1:10)  1 4 2 5 8 3 7 9 6 10 > sample(1:10)  6 3 9 5 10 2 7 1 8 4
Here we created a sample of size 10 three times and in all these samples the values are different.
Randomization with set.seed
> set.seed(99) > sample(1:10)  6 2 10 7 4 5 3 1 8 9 > set.seed(99) > sample(1:10)  6 2 10 7 4 5 3 1 8 9 > set.seed(99) > sample(1:10)  6 2 10 7 4 5 3 1 8 9
Since we used the same set.seed in all the three samples hence we obtained the same sample values.
- What is the use of set.seed in R?
- Why should we use MySQL CASE Statement?
- Why we should use whole string in Java regular expression
- Why should we not use an umbrella during lightning?
- What is SciPy and why should we use it?
- Why should we use fossil fuels only when absolutely necessary?
- Why should we use a StringBuffer instead of a String in Java?
- Why should we use wire netting in doors and windows of our homes?
- Why we should save electricity?
- Why should we conserve biodiversity?
- Why should I use Hubspot?
- Why do we need a copy constructor and when should we use a copy constructor in Java?