[R-sig-Geo] ReadShapePoly subsetting data

2010-05-30 Thread Peter Larson
Hello all, I have data for several states and no data for most. I just want to subset the states I have data for and ignore the rest. Is there anyway to do this? I have a shapefile and have read it in with ReadShapePoly successfully, but I don't need all 50 American states. Thanks, Pete

Re: [R-sig-Geo] ReadShapePoly subsetting data

2010-05-30 Thread Matt Beard
Have you looked into functions such as na.omit()? Matt On Sun, May 30, 2010 at 7:54 PM, Peter Larson pslars...@gmail.com wrote: Hello all, I have data for several states and no data for most. I just want to subset the states I have data for and ignore the rest. Is there anyway to do this?

Re: [R-sig-Geo] ReadShapePoly subsetting data

2010-05-30 Thread Peter Larson
They don't show up as NA's. They are just 0's. The 0 values in the states I am interested in are correct, however. Pete On 2010/05/30 20:28, Matt Beard wrote: Have you looked into functions such as na.omit()? Matt On Sun, May 30, 2010 at 7:54 PM, Peter Larson pslars...@gmail.com

Re: [R-sig-Geo] ReadShapePoly subsetting data

2010-05-30 Thread Matt Beard
Well, you need to find some variable to use for subsetting the data. Can you share an example of your data? Would something like the following work for you? stateID - c(AL,AK,AR,CA,DE,FL,GA,MN,WA,WI,WY) var1 - c(0,0,0,0,0,0,0,0,0,2,0) df - data.frame(stateID,var1) statesWanted - c(MN,WI)

Re: [R-sig-Geo] ReadShapePoly subsetting data

2010-05-30 Thread Peter Larson
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 -

Re: [R-sig-Geo] ReadShapePoly subsetting data

2010-05-30 Thread Don MacQueen
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

Re: [R-sig-Geo] ReadShapePoly subsetting data

2010-05-30 Thread Matt Beard
I believe Peter figured it out on his own off list. Here was my solution using rgdal: library(rgdal) # Shapefile's full path is '/home/matt/LynchingHotSpots. shp' on my computer # If you had your file at 'C:\data\LynchingHotSpots.shp' you would change #shpFolder to C:/data and