2016-05-18 2 views
0

J'essaie de créer une grille pour la modélisation. J'ai mis en place le code suivant:Reproductibilité avec l'échantillon

#--Grid Extents--# 
xmin <- 1712352.4170 
ymin <- 249753.9450 
xmax <- 1714452.4170 
ymax <- 252713.9450 

#--Set-up Grid--# 
library(sp) 
grd <- data.frame(x=c(xmin, xmax), y=c(ymin, ymax)) 
coordinates(grd) <- ~x+y 
grd <- data.frame(spsample(grd , nsig=1, type='regular', cellsize=c(20, 20))) 

pourquoi est-ce que chaque fois que je lance ce code (sans apporter de modifications) le data.frame grd a des valeurs différentes?

Exemple: Course 1

head(grd) 
    x1  x2 
1 1712367 249760.5 
2 1712387 249760.5 
3 1712407 249760.5 
4 1712427 249760.5 
5 1712447 249760.5 
6 1712467 249760.5 

Run 2:

head(grd) 
    x1  x2 
1 1712359 249764.2 
2 1712379 249764.2 
3 1712399 249764.2 
4 1712419 249764.2 
5 1712439 249764.2 
6 1712459 249764.2 

Voici mon numéro de session:

R version 3.1.3 (2015-03-09) 
Platform: x86_64-w64-mingw32/x64 (64-bit) 
Running under: Windows 8 x64 (build 9200) 

locale: 
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 
[4] LC_NUMERIC=C       LC_TIME=English_United States.1252  

attached base packages: 
[1] grid  stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] nlme_3.1-118  knitr_1.9   rasterVis_0.28  hexbin_1.26.3  latticeExtra_0.6-26 RColorBrewer_1.0-5 
[7] lattice_0.20-27  viridis_0.3.4   gstat_1.0-19  raster_2.2-12  rgeos_0.3-4   
[13] rgdal_0.9-1   sp_1.0-17   data.table_1.9.4 

loaded via a namespace (and not attached): 
[1] chron_2.3-45  colorspace_1.2-4 digest_0.6.8  evaluate_0.5.5 FNN_1.1   formatR_1.0  ggplot2_2.1.0 
[8] gridExtra_2.2.1 gtable_0.1.2  htmltools_0.2.6 intervals_0.14.0 munsell_0.4.2 plyr_1.8.1  Rcpp_0.12.2  
[15] reshape2_1.4  rmarkdown_0.3.11 scales_0.4.0  spacetime_1.1-0 stringr_0.6.2 tools_3.1.3  xts_0.9-7  
[22] yaml_2.1.13  zoo_1.7-11 
+1

Quelle est la sortie désirée? –

Répondre

1

parce que vous prenez un échantillon aléatoire. Essayez par exemple

set.seed(1) 

avant de configurer la grille, et vous obtiendrez les mêmes résultats.