Another approach that will probably be more work up front, but may be better in the long run if you are going to be doing a lot of this is to use the maptools and sp packages. Create a spatialpointsdataframe from your data, read in a us map (there are shapefiles that you can get from the US census bureau website or other places) as a spatialpolygondataframe and use the overlay methods to subset the data.
You may want to post future questions on this topic to the R-sig-geo list for more specific help. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] 801.408.8111 > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > project.org] On Behalf Of claudia tebaldi > Sent: Tuesday, October 07, 2008 4:09 PM > To: r-help@r-project.org > Subject: [R] masking a regular lat/lon grid to extract map boundaries > > Dear R-helpers, > > I have lat/lon coordinates of regularly spaced grid points, about 4Km > apart, covering the entire US continental region. > I would like to mask this rectangular grid in order to extract all and > only the grid points within a specific region. Today I want to > extract Montana, say, from this grid, and I am hoping to somehow use > the returned value of the function map("state",region="montana"). > I'm not espoused to using the "maps" library database, it's just the > way I thought one could go about it (one smarter than I am...) and it > would certainly be useful to exploit the many political boundaries > provided by that library, when I move on from Montana to something > else... > > Any suggestion for an algorithm to do this? > > Of course if someone out there has a high-res mask for the US states > I'll happily forget about using map(): I'll take it and interpolate > (or knn1) away to my grid! > > thank you in advance > > claudia > > -- > Claudia Tebaldi > Research Scientist, Climate Central > http://www.climatecentral.org > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.