[R-sig-Geo] ReadShapePoly subsetting data

Don MacQueen macq at llnl.gov
Mon May 31 06:18:40 CEST 2010


Supposing that your data object is named "mydata", try following this example:

   mydata[ , STATE_NAME %in% c('name1','name2','name17') ]

replacing my fake state names with the ones you want.

If you have another variable that identifies the subset you want, use 
it instead of STATE_NAME.

This example assumes you data is in a SpatialPolygonsDataFrame.

You haven't really provided enough information for more specific suggestions.

-Don

At 10:53 PM -0400 5/30/10, Peter Larson wrote:
>It doesn't seem to work. This what I have though.
>
>I have a STATE_NAME variable in the data that I could potentially 
>use, assuming I know the write syntax.
>
>Any ideas?
>
>Thanks!
>
>Pete
>
>nc_file <- system.file("/LynchingHotSpots.shp", package="maptools")[1]
>llCRS <- CRS("+proj=longlat +datum=NAD27")
>nc <- readShapePoly("LynchingHotSpots.shp",  proj4string=llCRS)
>
>statesWanted <- c("MN","WI")
>
>nc <- nc[nc$STATE_NAME %in% statesWanted,]
>
>
>print(spplot(nc, c("Lynchings")))
>
>_______________________________________________
>R-sig-Geo mailing list
>R-sig-Geo at stat.math.ethz.ch
>https://*stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
---------------------------------
Don MacQueen
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
macq at llnl.gov



More information about the R-sig-Geo mailing list