Simultaneous data generated when loading .RData

When loading the .RData file, the same random numbers are generated every time. For example, try the following: (Enter them in the terminal)

rm(list=ls())
x=10 #Just some random value 
save.image("samplefile.RData")

Now try this:
rm(list=ls())
load("samplefile.RData")
print(runif(n=100,min=0,max=100)) #Now it prints same random numbers everytime i run above code junket.

Can anyone please explain?

Thanks.
+4
source share
2 answers

If you need to load a .RData file with .Random.seed saved, you can reset to use samples using the clock time and this bit of code:

a <- as.numeric(Sys.time())
set.seed(a)

Note that there are benefits to accurately reproducing randomisations, i.e. reproducible studies. But for everyday purposes, it is probably safer to save and load objects, rather than the environment. https://www.rdocumentation.org/packages/base/versions/3.4.0/topics/readRDS

+1
source

-.Random.seed Rdata. , rm() .

+2

Source: https://habr.com/ru/post/1668156/


All Articles