如何找到最接近2个数字的值索引?

时间:2017-09-14 19:32:17

标签: r

我有一个数据框。我还有另一组lat-longs

xlat = 41.60180 (Example numbers)
xlong = -114.24000

我想找到最接近这些数字的行(和相应的varID)。我怎么能够?我怎样才能做到地理上的接近?

> dput(droplevels(head(df,50)))
structure(list(lat = structure(c(41.26124, 41.45247, 41.50923, 
41.57602, 41.62999, 41.60664, 41.63508, 41.83411, 41.84721, 41.84382, 
41.83294, 41.85096, 41.60179, 41.8572, 41.64224, 41.85058, 41.14342, 
41.77109, 41.35783, 41.39253, 41.78496, 41.5982, 41.66492, 41.70302, 
41.56481, 41.55544, 41.59929, 41.71257, 41.85876, 41.42739, 41.39722, 
41.76483, 41.49387, 41.46879, 41.50355, 41.95393, 41.8932, 41.96956, 
41.76675, 41.93061, 41.93767, 41.53439, 41.51667, 41.50472, 41.5053, 
41.67506, 41.68689, 41.78533, 41.79546, 41.87722), .Dim = 50L), 
    long = structure(c(-116.21489, -114.91972, -114.74541, -114.72553, 
    -114.83965, -114.81267, -114.84702, -113.49586, -113.48851, 
    -113.46151, -113.45017, -113.38449, -114.91356, -113.41496, 
    -114.85369, -113.50472, -116.21671, -114.25468, -116.32436, 
    -116.18391, -114.23875, -115.05154, -114.95098, -114.99438, 
    -115.75044, -115.89944, -115.84581, -114.9099, -114.19781, 
    -116.59131, -116.53819, -114.07782, -116.38066, -116.4347, 
    -116.33524, -113.51231, -113.51787, -113.55034, -114.96587, 
    -113.34303, -113.24616, -116.28699, -116.60549, -116.63497, 
    -116.55531, -115.19046, -114.72527, -114.64668, -114.54489, 
    -113.59969), .Dim = 50L), hrus = 1:50), .Names = c("lat", 
"long", "varID"), row.names = c(NA, 50L), class = "data.frame")

0 个答案:

没有答案