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 -0700 1/4/10, Douglas M. Hultstrand 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
and provide commented, minimal, self-contained, reproducible code.
--
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
______________________________________________
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.