简体   繁体   English

如何使用R计算以英里为单位的两个邮政编码之间的距离

[英]How to calculate Distance between Two Zipcodes in Miles Using R

I wanted to calculate the distance between two zip codes. 我想计算两个邮政编码之间的距离。 Is there any particular function to find the distance? 有没有找到距离的特定功能?

I used this code 我用了这段代码

Dataframe <- transform(dataframe, Distance = ifelse(a == "" | b == "", "", georoute( c("a", "b"), verbose=TRUE, returntype="distance", service="bing" )))

Where a and b are two separate columns which contain zipcodes of two different areas. 其中ab是两个单独的列,其中包含两个不同区域的邮政编码。

I used the code given at Determing the distance between two ZIP codes (alternatives to mapdist) 我使用了“ 确定两个邮政编码之间的距离”(mapdist的替代方法)中给出的代码

You can find online a table that has longitudes and latitudes for 29,000+ US cities, along with their zip codes. 您可以在线找到一张表格,其中包含29000多个美国城市的经度和纬度,以及它们的邮政编码。 with it you could then convert your columns of zip codes to coordinates. 有了它,您就可以将邮政编码列转换为坐标。

Then, the geosphere package offers eight functions for calculating distances (great circle, Haversine, Rhumb, etc) based on coordinates. 然后, geosphere软件包提供了八个功能,可根据坐标计算距离(大圆,Haversine,Rhumb等)。 It also converts meters to miles. 它还可以将米转换为英里。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM