Dear list,
 
The stratified random sampling problem that I submitted a few days ago has 
already been solved, with the help of several of you, notably Edzer Pebesma. 
Edzer came up with the following solution:
 
library(sp)
library(rgdal)
nc1 <- readShapePoly(system.file("shapes/sids.shp",package="maptools")[1], 
proj4string=CRS("+proj=longlat +datum=NAD27"))
pts = do.call(rbind, sapply(slot(nc1, "polygons"), spsample, n=1, 
type="random"))
plot(nc1)
points(pts, col='blue', pch=19, cex=1)
 
As it happened, the do.call statement did not work in my case (Edzer and Roger 
may look into why it does not work with all shapes) and had to be replaced by:
 
for (i in 1:length(slot(nc1, "polygons"))) {
    pt = spsample(nc1[i,], n=1, type="random")
    if (i == 1)
        pts = pt
    else
        pts = rbind(pts, pt)
}

I am so happy!

Gerard

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to