R 从一个点确定多个邮政编码之间的距离
我一直在使用mapdist函数()来确定两个ZipCode之间的距离。我还不太擅长循环,想知道如何在多个zipcodes中循环,这样我就不必每次都重新运行代码 代码贴在下面R 从一个点确定多个邮政编码之间的距离,r,R,我一直在使用mapdist函数()来确定两个ZipCode之间的距离。我还不太擅长循环,想知道如何在多个zipcodes中循环,这样我就不必每次都重新运行代码 代码贴在下面 library(ggmap) mapdist('95077','06473', mode = 'driving') 构建示例data.frame geoData <- data.frame(FROM = c('95077', 'Manchester Deaf Institute'),
library(ggmap)
mapdist('95077','06473', mode = 'driving')
构建示例data.frame
geoData <- data.frame(FROM = c('95077', 'Manchester Deaf Institute'),
TO = c('06473', 'Birmingham O2 Academy 1'),
stringsAsFactors = FALSE)
结果
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
你不太可能做一个循环。您可以将一个向量和所有
从
(mapdist的第一个参数)传递给一个向量,并将一个向量和所有传递给
(函数的第二个参数)。ggmap现在是一项付费服务,因此您可以使用geosphere,如本文所示:
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