Or if there is a requirement for speed or shorter more convenient syntax
then there is a data.table join.
Basically setkey(data1,V1,V2) and setkey(data2,V1,V2), then data1[data2]
does the merge very quickly. You probably then want to do something with the
merged data set, which you just add
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
I guess you want the subset of data whose lat/long pairs are
present in data2?
Try renaming your columns so that V1 and V2 are the same in both data
frames (either lat,long, or long,lat, but not one way in one
dataframe and the other way in the other one.
Then use merge()
-Don
At 5:37 PM
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)
V1V2 V3 V1V2
1 -123.76 47.82 8 -123.76 47.82
2
4 matches
Mail list logo