

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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.
Example
Randomization without set.seed
> sample(1:10) [1] 4 10 5 3 1 6 9 2 8 7 > sample(1:10) [1] 1 4 2 5 8 3 7 9 6 10 > sample(1:10) [1] 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) [1] 6 2 10 7 4 5 3 1 8 9 > set.seed(99) > sample(1:10) [1] 6 2 10 7 4 5 3 1 8 9 > set.seed(99) > sample(1:10) [1] 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.
- Related Questions & Answers
- Why should we use MySQL CASE Statement?
- Why should we not use ++, -- operators in JavaScript?
- What is the use of set.seed in R?
- What is SciPy and why should we use it?
- Why should we use <noscript> element in JavaScript?
- Why we should use whole string in Java regular expression
- Why should I use Hubspot?
- Why should we use a semicolon after every function in JavaScript?
- 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?
Advertisements