[R-sig-Geo] subselection of Polygons

Stéphane Dray dray at biomserv.univ-lyon1.fr
Fri Mar 2 11:24:18 CET 2007


Hello list,

I have a question concerning the [ operator for SPDF. Consider the 
following example :

library(maptools)
xx <- readShapePoly(system.file("shapes/sids.shp", package="maptools")[1], IDvar="FIPSNO", proj4string=CRS("+proj=longlat +ellps=clrk66"))
plot(xx, border="blue", axes=TRUE, las=1)
text(getSpPPolygonsLabptSlots(xx), labels=getSpPPolygonsIDSlots(xx), cex=0.6)
as(xx, "data.frame")[1:5, 1:6]
xxx <- xx[xx$SID74 < 2,]

The last line is equivalent to :

xxx <- xx[which(xx$SID74 < 2),]

I supposed that I can easily have the inverse selection by using '-' but 
it does not work :

xxx <- xx[which(xx$SID74 < 2),]

returns the following error message :

Erreur dans validObject(.Object) : invalid class "SpatialPolygons" 
object: length mismatch

I do not understand what is the problem (sp 0.9-8, R 2.4.0).

Thanks,

-- 
Stéphane DRAY (dray at biomserv.univ-lyon1.fr )
Laboratoire BBE-CNRS-UMR-5558, Univ. C. Bernard - Lyon I
43, Bd du 11 Novembre 1918, 69622 Villeurbanne Cedex, France
Tel: 33 4 72 43 27 57       Fax: 33 4 72 43 13 88
http://biomserv.univ-lyon1.fr/~dray/




More information about the R-sig-Geo mailing list