Michael, Thank you for the tips. The suggestion didn't work though. Here is the output of str(e): Formal class 'SpatialPointsDataFrame' [package "sp"] with 5 slots ..@ data :'data.frame': 168 obs. of 2 variables: .. ..$ catchcandata: num [1:168] 47.2 50.4 53.7 58 69.8 ... .. ..$ section : Factor w/ 1 level "16 Sept F9": 1 NA NA NA NA NA NA NA NA NA ... ..@ coords.nrs : int [1:2] 1 2 ..@ coords : num [1:168, 1:2] 0 0 0 0 0 ... .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : NULL .. .. ..$ : chr [1:2] "x" "y" ..@ bbox : num [1:2, 1:2] 0 0 48.8 17.1 .. ..- attr(*, "dimnames")=List of 2 .. .. ..$ : chr [1:2] "x" "y" .. .. ..$ : chr [1:2] "min" "max" ..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slots .. .. ..@ projargs: chr NA
-----Original Message----- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Thursday, October 13, 2011 11:13 AM To: Bailey, Daniel Cc: Sarah Goslee; r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame It's going to depend how the coordinates are stored within the data frame. Do you perhaps know if they are factors or character strings? (I'm not familiar with the package). If you don't know, type str(NAMEOFYOUROBJECT) and we can help interpret the output. Untested, I think this would actually work for both though: e[as.character(e$coordinates)=="(0,17)",] Michael On Thu, Oct 13, 2011 at 2:05 PM, Bailey, Daniel <bai...@spu.edu> wrote: > Thank you Sarah. I tried your suggestion, and if I coerce it into a normal > data.frame, that method works. But if you've already made the data into a > SpatialPixelsDataFrame and run coordinates (both from the package "sp") so > that the columns "x" and "y" become a single column "coordinates" with the > format (0, 17) for x and y, how do you then call or manipulate data at a > specific location? > > The following: > e[e$coordinates==(0,17),] > Doesn't work. > > > -----Original Message----- > From: Sarah Goslee [mailto:sarah.gos...@gmail.com] > Sent: Wednesday, October 12, 2011 5:34 PM > To: Bailey, Daniel > Cc: r-help@r-project.org > Subject: Re: [R] getting data associated with coordinates in a spatial > data frame > > Hi, > > On Wed, Oct 12, 2011 at 3:37 PM, Bailey, Daniel <bai...@spu.edu> wrote: >> If I know the specific coordinate in a spatial data frame, how can I access >> the data at that coordinate? >> >> My coordinates are labeled "x" and "y" in a data.frame "e". The data is in >> column "leachate". >> I want to say, basically: >> e$leachate@coordinates(2,3<mailto:e$leachate@coordinates(2,3>). > > That's kind of mangled, but what about: > > e[e$x == my.x & e$y == my.y, "leachate"] > > (Depending on the form of your coordinates, you may also have to > invoke FAQ 7.31.) > > Sarah > >> Thanks, Daniel >> > > -- > Sarah Goslee > http://www.functionaldiversity.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.