Hi Jin, >From your description it is not entirely clear what your input data looks like. But you can something like this
library(raster) p <- read.table('points.txt') r <- raster('file.asc') values<- extract(r, p) Perhaps you need to subset "p" to get the appropriate columns representing longitude and latitude (in that order). Or perhaps your grid data is not really in a 'raster' format? I am not sure from your description. In that case you may need to to d <- read.table('file.asc') r <- rasterFromPoints(d) You may also want to check out functions cellFromXY to link coordinates to cells in a raster. All the best, Robert On Wed, Oct 3, 2012 at 5:38 PM, <jin...@ga.gov.au> wrote: > Dear list, > > I have two datasets: one is for point samples with lat and long > information at accuracy of 0.001 degrees. Another is grid cells at a > resolution of 0.0025 degrees. Both datasets are in txt format. Now I need > to extract the lat and long information from the grid cell dataset for the > point samples by assigning the lat and long of a grid cell to a sample > point that falls in the grid cell. I usually get this done in ArcGIS. I was > wondering if it is possible in R. I searched but failed to find a right > function to implement this in R. > > Many thanks for any suggestions. > > Regards, > > Jin Li > Spatial Modeller/Computational Statistician | Coastal, Marine and > Climate Change Group > Environmental Geoscience Division | GEOSCIENCE AUSTRALIA > ____________________________________________________________ > Phone: +61 2 6249 9899 Fax: +61 2 6249 9999 > Email: jin...@ga.gov.au<mailto:jin...@ga.gov.au> Web: www.ga.gov.au< > http://www.ga.gov.au/> > Cnr Jerrabomberra Avenue and Hindmarsh Drive Symonston ACT > GPO Box 378 Canberra ACT 2601 Australia > Applying geoscience to Australia's most important challenges > > > Geoscience Australia Disclaimer: This e-mail (and files transmitted with > it) is intended only for the person or entity to which it is addressed. If > you are not the intended recipient, then you have received this e-mail by > mistake and any use, dissemination, forwarding, printing or copying of this > e-mail and its file attachments is prohibited. The security of emails > transmitted cannot be guaranteed; by forwarding or replying to this email, > you acknowledge and accept these risks. > > ------------------------------------------------------------------------------------------------------------------------- > > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo