Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 从一个点确定多个邮政编码之间的距离_R - Fatal编程技术网

R 从一个点确定多个邮政编码之间的距离

R 从一个点确定多个邮政编码之间的距离,r,R,我一直在使用mapdist函数()来确定两个ZipCode之间的距离。我还不太擅长循环,想知道如何在多个zipcodes中循环,这样我就不必每次都重新运行代码 代码贴在下面 library(ggmap) mapdist('95077','06473', mode = 'driving') 构建示例data.frame geoData <- data.frame(FROM = c('95077', 'Manchester Deaf Institute'),

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

代码贴在下面

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