简体   繁体   English

与在excel中计算相同事​​物时,在R中使用distm函数计算两个坐标之间的距离可得出不同的答案

[英]Using distm function in R to calculate distance between two coordinates gives a different answer than when calculating the same thing in excel

I'm trying to calculate the distance between two coordinates (40.777250, -73.872610) and (40.6895, -74.1745) . 我正在尝试计算两个坐标(40.777250, -73.872610) and (40.6895, -74.1745)之间的距离。

Using distm in R gives the following result: 在R中使用distm可获得以下结果:

> distm (c(40.777250, -73.872610), c(40.6895, -74.1745), fun = distHaversine)

33713.61

When I use Excel to calculate the distance with the following function 当我使用Excel通过以下函数计算距离时

6378134 * ACOS(COS(RADIANS(90-40.777250)) *COS(RADIANS(90-40.6895)) +SIN(RADIANS(90-40.777250)) *SIN(RADIANS(90-40.6895)) *COS(RADIANS(-73.872610-(-74.1745))))

the answer is 27274.49199 . 答案是27274.49199

I'm wondering why these two methods give a different answer and whether I'm doing something wrong. 我想知道为什么这两种方法给出了不同的答案,以及我是否做错了什么。 I tried an online coordinate distance calculator and it gives the same answer as my excel function. 我尝试了一个在线坐标距离计算器,它给出的答案与我的excel函数相同。

You have to change the order of longitude and latitude , because (see vignette): 您必须更改经度和纬度的顺序,因为(请参见插图):

Geographic locations must be specified in longitude and latitude (and in that order!) 必须按经度和纬度(并按此顺序!)指定地理位置。

result <- distm (c(-73.872610,40.777250), c(-74.1745, 40.6895), fun = distHaversine)
#         [,1]
# [1,] 27274.5

or: 要么:

distHaversine(c(-73.872610,40.777250), c(-74.1745, 40.6895))
# [1] 27274.5

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Distm function 用于计算 R 中坐标之间的距离 - Distm function for calculate distance between coordinates in R 使用mutate中的distm函数计算两点之间的距离 - Calculating distance between two points using the distm function inside mutate 使用R中的distm()计算数据帧中两个GPS位置之间的距离 - Calculating distance between two GPS locations in a data frame using distm () in R 计算R中同一行的2个坐标之间的距离 - Calculate the distance between 2 coordinates in the same row in R 使用distm(distVincentyEllipsoid)将点子集(相同ID)之间的平均大地测量距离并将结果存储在R中的新数据框中 - Average geodetic distance between subsets of points (same ID) using distm(distVincentyEllipsoid) and storing the results in a new dataframe in R R:大数据的区别? 计算两个矩阵之间的最小距离 - R: Distm for big data? Calculating minimum distances between two matrices 计算坐标R之间的距离 - Calculating the distance between coordinates R distm 函数,比较 2 个坐标的列表(2 组长/纬度坐标)并找出它们之间的距离 - distm function, to compare a list of 2 coordinates (2 sets of long/lat coordinates) and find distance between them 计算 R 中坐标之间的距离 - Calculate distance between coordinates in R 计算R中不同ID长度的个体在两个坐标列组之间的距离 - Calculate the distance between two coordinates columns group by individuals of different ID length in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM