[GRASS-stats] random subset in R

Roger Bivand Roger.Bivand at nhh.no
Mon Jun 14 15:22:30 EDT 2010

On Mon, 14 Jun 2010, Leonardo Hardtke wrote:

> Hi list,
> I'm tryng to do a simple random subset of spatial points in R and don't know 
> how....
> I tried:
> library(spgrass6)
> hs=readVECT6("HSd01 at Hot_Spot") (3500 point) #SpatialPointDataFrame
> hs_smpl=spsample(hs, 200, "random")  #->SpatialPoints

Why do you thing that this is a subsample of your points? It is a sample 
of 200 points in the bounding box of your points, I think. To subsample, 
generate a new object by subsetting on row indices in the sample:

coordinates(meuse) <- c("x", "y")
plot(meuse, axes=TRUE)
plot(spsample(meuse, n=50, type="random"), col="red", add=TRUE)
plot(meuse[sample(x=nrow(meuse), size=50),], col="blue", pch=16, add=TRUE)

Hope this helps,


> the question is... how do I attach the right data?
> Thanks!
> Leonardo Hardtke
> _______________________________________________
> grass-stats mailing list
> grass-stats at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-stats

Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no

More information about the grass-stats mailing list