【问题标题】:Determining the distance between multiple ZIP codes from one point从一个点确定多个邮政编码之间的距离
【发布时间】:2018-05-18 16:08:54
【问题描述】:

我一直在使用 mapdist 函数()来确定两个邮政编码之间的距离。我还不太擅长循环,想知道如何在多个邮政编码中循环,这样我就不必每次都重新运行代码。

下面发布的代码。

library(ggmap)
mapdist('95077','06473', mode = 'driving')

【问题讨论】:

  • 您不太可能出现循环。您可以传递一个带有所有from(mapdist 的第一个参数)的向量和一个带有所有to(函数的第二个参数)的向量。

标签: r


【解决方案1】:
library(ggmap)

构建示例 data.frame

geoData <- data.frame(FROM = c('95077', 'Manchester Deaf Institute'),
                  TO = c('06473', 'Birmingham O2 Academy 1'), 
                  stringsAsFactors = FALSE) 

将列作为参数传递

mapdist(from = geoData[['FROM']], 
    to   = geoData[['TO']], 
    mode = 'driving')

结果

                       from                      to       m       km      miles seconds   minutes     hours
1                     95077                   06473 4932333 4932.333 3064.95173  161558 2692.6333 44.877222
2 Manchester Deaf Institute Birmingham O2 Academy 1  141330  141.330   87.82246    6569  109.4833  1.824722

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-26
  • 1970-01-01
  • 2013-01-01
  • 1970-01-01
  • 2014-06-09
相关资源
最近更新 更多