您可以创建具有位置之间距离的二维矩阵。geosphere
具有为您完成繁重工作的功能。
library(geosphere)
library(magrittr)
g_lat <- c(45.52306, 40.26719, 34.05223, 37.38605, 37.77493)
g_long <- c(-122.67648,-86.13490, -118.24368, -122.08385, -122.41942)
m <- cbind(g_long, g_lat)
(matrix <- distm(m) / 1609.34)
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 0.0000 1872.882 825.4595 562.3847 534.8927
#> [2,] 1872.8818 0.000 1812.5862 1936.5786 1946.4373
#> [3,] 825.4595 1812.586 0.0000 315.2862 347.3751
#> [4,] 562.3847 1936.579 315.2862 0.0000 32.5345
#> [5,] 534.8927 1946.437 347.3751 32.5345 0.0000
matrix < 50
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] TRUE FALSE FALSE FALSE FALSE
#> [2,] FALSE TRUE FALSE FALSE FALSE
#> [3,] FALSE FALSE TRUE FALSE FALSE
#> [4,] FALSE FALSE FALSE TRUE TRUE
#> [5,] FALSE FALSE FALSE TRUE TRUE
colSums(matrix < 50)
#> [1] 1 1 1 2 2
Created on 2018-09-16 by the [reprex package](http://reprex.tidyverse.org) (v0.2.0).