- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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.
- Why should we use MySQL CASE Statement?
- What is the use of set.seed in R?
- What is SciPy and why should we use it?
- Why we should use whole string in Java regular expression
- Why should I use Hubspot?
- Why should we use a StringBuffer instead of a String in Java?
- Why we use std:??
- Why do we need a copy constructor and when should we use a copy constructor in Java?
- Why we should avoid using std::endl in C++
- Why we should follow the naming conventions in Java?
- Why You Should Use an Anonymous Proxy Server?
- Why should eval be avoided in Bash, and what should I use instead?