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.
Aucun commentaire:
Enregistrer un commentaire