Many times I have seen the set.seed function in R, before starting the program. I know it's basically used for the random number generation. Is there any specific need to set this?
Jun 1, 2022 222 views

## 1 answer to this question.

The requirement is a desire for repeatable results, which may arise from attempting to debug your software or, of course, from attempting to redo what it does:

We will "never" reproduce these two findings because I specifically requested something "random":

R> an example (LETTERS, 5)
[1] "K" "N" "R" "Z" "G" "K" "N" "R" "Z" "G"
R> an example (LETTERS, 5)
[1] "L" "P" "J" "E" "D" "L" "P" "J" "E" "D" "L" "P" "
These two, on the other hand, are identical since the seed was planted by me:

R> sample.seed(42); set.seed(42); (LETTERS, 5)
[1] set.seed(42); sample "X" "Z" "G" "T" "O" R> set.seed(42); sample "X" "Z" "G" "T" "O" R> set.seed(42); (LETTERS, 5)
[1] R> "X" "Z" "G" "T" "O" R> "X" "Z" "G" "T" "O" R> "X" "Z
There's a lot of information out there; Wikipedia is a fantastic place to start. In essence, these RNGs are known as Pseudo Random Number Generators because they are totally algorithmic: given the input, they generate a random number.
answered Jun 20, 2022 by
• 3,040 points

## To speed up the tapply function in R, or another function to convert data frame into a matrix

I must turn a sizable dataset into ...READ MORE

## NA while using strptime function

Version 1.0.136 of R Studio for Windows ...READ MORE

## Understanding of minbucket function in CART model using R

Let's say that the training data is ...READ MORE

## Converting xlsx to xls using Microsoft Office Compitablity Pack's excelcnv

Simply rearranging the positions of the parameters ...READ MORE

## How to sample n random rows per group in a dataframe?

You can assign a random ID to ...READ MORE

## Choose specific number with probability

Examine the sample function. set.seed(1) sample(c(0,1), size=12, replace=TRUE, prob=c(0.2,0.8)) 1 ...READ MORE

## Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE