Andrew McFadden
2008-May-06 21:22 UTC
[R] Spatial join between two datasets using x and y co-ordinates
Hi R users I am trying to create a spatial join between two datasets. The first data set is large and contains descriptive data including x and y co-ordinates. The second dataset is small and has been selected spatially. The only data contained within the second dataset is the x and y coordinates only i.e. no descriptive data. The aim of a join made between the two datasets is to select those points (and hence all the descriptive data) from dataset one that has the same x and y co-ordinates as dataset two. x1<-c(1824615,1823650,1821910) y1<-c(5980732,5983220,5990931) descript<-c("cat", "dog", "horse") dat1<-data.frame(x1,y1,descript) x2<-c(1824615,1823650) y2<-c(5980732,5983220) dat2<-data.frame(x2,y2) dat1 dat2 The aim of the join is to produce: x1 y1 descript 1 1824615 5980732 cat 2 1823650 5983220 dog And therefore limit the data in dataset 1 to that which has the same x and y co-ordinates as dataset 2. Any suggestions? Regards Andy Andrew McFadden MVS BVSc Incursion Investigator Investigation & Diagnostic Centres - Wallaceville Biosecurity New Zealand Ministry of Agriculture and Forestry Phone 04 894 5600 Fax 04 894 4973 Mobile 029 894 5611 Postal address: Investigation and Diagnostic Centre- Wallaceville Box 40742 Ward St Upper Hutt ######################################################################## This email message and any attachment(s) is intended solely for the addressee(s) named above. The information it contains is confidential and may be legally privileged. Unauthorised use of the message, or the information it contains, may be unlawful. If you have received this message by mistake please call the sender immediately on 64 4 8940100 or notify us by return email and erase the original message and attachments. Thank you. The Ministry of Agriculture and Forestry accepts no responsibility for changes made to this email or to any attachments after transmission from the office. ######################################################################## [[alternative HTML version deleted]]
Peter Alspach
2008-May-06 22:29 UTC
[R] Spatial join between two datasets using x and y co-ordinates
Andrew ?merge HTH ...... Peter Alspach> -----Original Message----- > From: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] On Behalf Of Andrew McFadden > Sent: Wednesday, 7 May 2008 9:23 a.m. > To: r-help at r-project.org > Subject: [R] Spatial join between two datasets using x and y > co-ordinates > > Hi R users > > I am trying to create a spatial join between two datasets. > > The first data set is large and contains descriptive data > including x and y co-ordinates. > > The second dataset is small and has been selected spatially. > The only data contained within the second dataset is the x > and y coordinates only i.e. no descriptive data. > > The aim of a join made between the two datasets is to select > those points (and hence all the descriptive data) from > dataset one that has the same x and y co-ordinates as dataset two. > > x1<-c(1824615,1823650,1821910) > y1<-c(5980732,5983220,5990931) > descript<-c("cat", "dog", "horse") > dat1<-data.frame(x1,y1,descript) > > x2<-c(1824615,1823650) > y2<-c(5980732,5983220) > dat2<-data.frame(x2,y2) > > dat1 > dat2 > > The aim of the join is to produce: > > x1 y1 descript > 1 1824615 5980732 cat > 2 1823650 5983220 dog > > And therefore limit the data in dataset 1 to that which has > the same x and y co-ordinates as dataset 2. > > Any suggestions? > > Regards > > Andy > > > Andrew McFadden MVS BVSc > Incursion Investigator > Investigation & Diagnostic Centres - Wallaceville Biosecurity > New Zealand Ministry of Agriculture and Forestry > > Phone 04 894 5600 Fax 04 894 4973 Mobile 029 894 5611 Postal address: > Investigation and Diagnostic Centre- Wallaceville Box 40742 > Ward St Upper Hutt > > > > > > ############################################################## > ########## > This email message and any attachment(s) is intended solely for the > addressee(s) named above. The information it contains is confidential > and may be legally privileged. Unauthorised use of the > message, or the > information it contains, may be unlawful. If you have received this > message by mistake please call the sender immediately on 64 4 8940100 > or notify us by return email and erase the original message and > attachments. Thank you. > > The Ministry of Agriculture and Forestry accepts no responsibility for > changes made to this email or to any attachments after > transmission from > the office. > ############################################################## > ########## > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >The contents of this e-mail are privileged and/or confidential to the named recipient and are not to be used by any other person and/or organisation. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail.
Yasir Kaheil
2008-May-06 23:24 UTC
[R] Spatial join between two datasets using x and y co-ordinates
vector dat1.select is the selected records from dat1 by dat2.> dat1.select<- dat1$x1 %in% dat2$x2 & dat1$y1 %in% dat2$y2 > dat1[dat1.select,]x1 y1 descript 1 1824615 5980732 cat 2 1823650 5983220 dog Andrew McFadden wrote:> > Hi R users > > I am trying to create a spatial join between two datasets. > > The first data set is large and contains descriptive data including x > and y co-ordinates. > > The second dataset is small and has been selected spatially. The only > data contained within the second dataset is the x and y coordinates only > i.e. no descriptive data. > > The aim of a join made between the two datasets is to select those > points (and hence all the descriptive data) from dataset one that has > the same x and y co-ordinates as dataset two. > > x1<-c(1824615,1823650,1821910) > y1<-c(5980732,5983220,5990931) > descript<-c("cat", "dog", "horse") > dat1<-data.frame(x1,y1,descript) > > x2<-c(1824615,1823650) > y2<-c(5980732,5983220) > dat2<-data.frame(x2,y2) > > dat1 > dat2 > > The aim of the join is to produce: > > x1 y1 descript > 1 1824615 5980732 cat > 2 1823650 5983220 dog > > And therefore limit the data in dataset 1 to that which has the same x > and y co-ordinates as dataset 2. > > Any suggestions? > > Regards > > Andy > > > Andrew McFadden MVS BVSc > Incursion Investigator > Investigation & Diagnostic Centres - Wallaceville Biosecurity New > Zealand Ministry of Agriculture and Forestry > > Phone 04 894 5600 Fax 04 894 4973 Mobile 029 894 5611 Postal address: > Investigation and Diagnostic Centre- Wallaceville Box 40742 Ward St > Upper Hutt > > > > > > ######################################################################## > This email message and any attachment(s) is intended solely for the > addressee(s) named above. The information it contains is confidential > and may be legally privileged. Unauthorised use of the message, or the > information it contains, may be unlawful. If you have received this > message by mistake please call the sender immediately on 64 4 8940100 > or notify us by return email and erase the original message and > attachments. Thank you. > > The Ministry of Agriculture and Forestry accepts no responsibility for > changes made to this email or to any attachments after transmission from > the office. > ######################################################################## > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. > >----- Yasir H. Kaheil, Ph.D. Catchment Research Facility The University of Western Ontario -- View this message in context: http://www.nabble.com/Spatial-join-between-two-datasets-using-x-and-y-co-ordinates-tp17093486p17093656.html Sent from the R help mailing list archive at Nabble.com.
Jorge Ivan Velez
2008-May-06 23:37 UTC
[R] Spatial join between two datasets using x and y co-ordinates
Hi Andrew, Try also: x1<-c(1824615,1823650,1821910) y1<-c(5980732,5983220,5990931) descript<-c("cat", "dog", "horse") dat1<-data.frame(x1,y1,descript) x2<-c(1824615,1823650) y2<-c(5980732,5983220) dat2<-data.frame(x2,y2) colnames(dat2)=c('x1','y1') merge(dat1,dat2,by=c('x1','y1')) HTH, Jorge On Tue, May 6, 2008 at 5:22 PM, Andrew McFadden <Andrew.McFadden@maf.govt.nz> wrote:> Hi R users > > I am trying to create a spatial join between two datasets. > > The first data set is large and contains descriptive data including x > and y co-ordinates. > > The second dataset is small and has been selected spatially. The only > data contained within the second dataset is the x and y coordinates only > i.e. no descriptive data. > > The aim of a join made between the two datasets is to select those > points (and hence all the descriptive data) from dataset one that has > the same x and y co-ordinates as dataset two. > > x1<-c(1824615,1823650,1821910) > y1<-c(5980732,5983220,5990931) > descript<-c("cat", "dog", "horse") > dat1<-data.frame(x1,y1,descript) > > x2<-c(1824615,1823650) > y2<-c(5980732,5983220) > dat2<-data.frame(x2,y2) > > dat1 > dat2 > > The aim of the join is to produce: > > x1 y1 descript > 1 1824615 5980732 cat > 2 1823650 5983220 dog > > And therefore limit the data in dataset 1 to that which has the same x > and y co-ordinates as dataset 2. > > Any suggestions? > > Regards > > Andy > > > Andrew McFadden MVS BVSc > Incursion Investigator > Investigation & Diagnostic Centres - Wallaceville Biosecurity New > Zealand Ministry of Agriculture and Forestry > > Phone 04 894 5600 Fax 04 894 4973 Mobile 029 894 5611 Postal address: > Investigation and Diagnostic Centre- Wallaceville Box 40742 Ward St > Upper Hutt > > > > > > ######################################################################## > This email message and any attachment(s) is intended solely for the > addressee(s) named above. The information it contains is confidential > and may be legally privileged. Unauthorised use of the message, or the > information it contains, may be unlawful. If you have received this > message by mistake please call the sender immediately on 64 4 8940100 > or notify us by return email and erase the original message and > attachments. Thank you. > > The Ministry of Agriculture and Forestry accepts no responsibility for > changes made to this email or to any attachments after transmission from > the office. > ######################################################################## > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >[[alternative HTML version deleted]]