jeudi 3 mars 2016

Confused about set.seed() called in functions in R

I have some functions which use random number generation statmood::rinvgauss().

For reproducibility I set up a set.seed call in the function:

my.fn <- function(days = 1:365, seed = 1000){
    set.seed(seed)

    #rinvgauss() call
    #etc...
}

But every time I run the function I get a different set of numbers. If I use set.seed outside the function it does work once, just the first time after I source the R script where all the code is.

Any ideas?




Aucun commentaire:

Enregistrer un commentaire