我有一个简化的数据框,如下所示:
dat <- data.frame(longitude = c(80.15998, 72.89125, 77.65032, 77.60599),
latitude = c(12.90524, 19.08120, 12.97238, 12.90927),
site = c("a", "b", "c", "d"),
source = c("K", "K", "P", "P"))
我想弄清楚如何找到每个可能的站点配对之间的距离(所以配对a-b,a-c,a-d,b-c等)。所以最终结果可能看起来像
a b c d
a
b
c
d
明显地填补了距离。
我知道我应该使用library(geosphere)
和distm()
或distHaversine()
的距离吗?
感谢任何帮助!