0

I want to use the sample function after setting set.seed with a fixed number. Unfortunately I obtain different results from a edx website. I'm wondering why I get different results. In the website they obtain 0.2706222. On my computer I obtain 0.3293778

I realized that the problem came from my sample function which do not returns me the same sample. Setting set.seed(1) and using sample(seq(1:5000), 3). My computer returns 1017 4775 2177 whereas it "should be" 1328 1861 2864

library(downloader) 
url <- "https://raw.githubusercontent.com/genomicsclass/dagdata/master/inst/extdata/femaleControlsPopulation.csv"
input_file <- basename(url)
download(url, destfile=input_file)
x <- unlist( read.csv(input_file) )
set.seed(1)
my_sample <- sample(x,5)
abs(mean(my_sample)-mean(x))

The expected output of the code computing the mean should be 0.2706222.

double-beep
  • 5,031
  • 17
  • 33
  • 41
masmalito
  • 1
  • 1
  • 1
    With R 3.6.0 are some changes in RNG. https://cran.r-project.org/doc/manuals/r-release/NEWS.html – jogo May 29 '19 at 09:09
  • 1
    [Is set.seed consistent over different versions of R (and Ubuntu)? - Stack Overflow](https://stackoverflow.com/questions/47199415/is-set-seed-consistent-over-different-versions-of-r-and-ubuntu) // [Same seed, different OS, different random numbers in R - Stack Overflow](https://stackoverflow.com/questions/48626086/same-seed-different-os-different-random-numbers-in-r?noredirect=1&lq=1) – user202729 May 29 '19 at 09:10
  • Hi jogo, thank you very much for your answer. Problem solved using: `RNGKind(sample.kind="Rounding")` – masmalito May 29 '19 at 11:52

0 Answers0