couple of approaches:

> merge(data1, data2, by.x=c("V1", "V2"), by.y=c("V2", "V1"))
     V1      V2 V3
1 47.82 -123.75 11
2 47.82 -123.76  8
> library(sqldf)
> sqldf("select * from data2 x2, data1 x1 where x2.V1=x1.V2 and
x2.V2=x1.V1")
       V1    V2 V3      V1    V2
1 -123.76 47.82  8 -123.76 47.82
2 -123.75 47.82 11 -123.75 47.82
>


On Mon, Jan 4, 2010 at 7:37 PM, Douglas M. Hultstrand
<dmhul...@metstat.com>wrote:

> Hello,
>
> I am trying to match lat/lon from one dataset with the lat/lon from a
> second dataset and use that rows data for calculations.  I am using match,
> but this is finding the first match and not comparing the pair, how can I
> determine if the lat/lon are the same?  See example below.  Is there a
> better way to determine to a matching pair of lat/lon values?
>
> Example Datasets:
> > data2
>      V1    V2 V3
> 1 -123.76 47.82  8
> 2 -123.75 47.82 11
>
> > data[1:2]
>     V1      V2
> 1  47.82 -123.76
> 2  47.82 -123.75
> 3  47.82 -123.74
> 4  47.82 -123.73
>
> #Subset of current R code :
> lat <- data$V1
> lon <- data$V2
> yrs <- c(1,2,5,10,25,50,100,200,500,1000)
> lon2 <- data2$V1
> lat2 <- data2$V2
> ppt2 <- data2$V3
>
> for(i in 1:length(lat2)) {
>       loc <- match(lat2[i],lat)
>       loc2 <- match(lon2[i], lon)
>       print(loc); print(loc2)
>
>       #Need to test to make sure loc equals loc2
>       freq_ppt <-
> c(data[i,4],data[i,6],data[i,8],data[i,10],data[i,12],data[i,14],data[i,16],data[i,18],data[i,20],data[i,22])
>       print(freq_ppt)
>       return_value <- approx(freq_ppt,yrs,xout=data2[i,3])
>       print(return_value)
> }
>
>
> Thanks for your help,
> Doug
>
> --
> ---------------------------------
> Douglas M. Hultstrand, MS
> Senior Hydrometeorologist
> Metstat, Inc. Windsor, Colorado
> voice: 970.686.1253
> email: dmhul...@metstat.com
> web: http://www.metstat.com
>
> ______________________________________________
> 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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[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.

Reply via email to