[R-sig-Geo] sampleStratified Error

Michael Koehler michael.koehler at nw-fva.de
Fri Dec 5 11:20:55 CET 2014


Dear R-sig-geo users,

I have a large Rasterlayer with integers ranging from 0 to 44.

class       : RasterLayer
dimensions  : 29800, 34470, 1027206000  (nrow, ncol, ncell)
resolution  : 10, 10  (x, y)
extent      : 331300, 676000, 5681995, 5979995  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=32 +ellps=GRS80 +units=m +no_defs
data source : /home/mkoehler/stk_rast_whz
names       : stk_rast_whz
values      : 0, 44  (min, max)

I want to do a stratified sampling of 5000 points per stratum.
I get the following error:
POINTS<-sampleStratified(b, size=5000, na.rm=T, xy=F)
(Error in ys[[i]] <- y : attempt to select less than one element)

Here is a code that reproduces the problems (even when only selecting 1 
item per stratum):

 > set.seed(10)
 > r <- raster(ncol=5000, nrow=5000)
 > names(r) <- 'stratum'
 > r[] <- round((runif(ncell(r)))*44)
 > #plot(r)
 >
 > sampleStratified(r, size=1,xy=T)
Error in ys[[i]] <- y : attempt to select less than one element

Trying that with fewer strata and changing the settings of "size" or 
"exp" have no effect.
R version: [64-bit] C:\Program Files\R\R-3.1.1


Any ideas?

thanks in advance!

-- 
Michael Köhler



More information about the R-sig-Geo mailing list