且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

计算数据框中两个长纬度坐标之间的距离

更新时间:2022-12-09 13:40:20

鉴于您要存储在新列中的输出是这样的:

Given that the output you want to store in the new column is this:

77.54033 135.23165

尝试一下

df$distance<-distHaversine(df[,1:2], df[,3:4])

哪个应该回来

> df
      lat1     lon1     lat2     lon2  distance
1 7.348687 53.36575 7.348940 53.36507  77.54033
2 7.348940 53.36507 7.350939 53.36484 135.23165