我正在尝试修复以下代码以计算国家与边界之间的距离。我相信,该代码不起作用,因为包是在旧版本的 R 中完成的,不再受支持。但这只是猜测。
我试图开始工作的代码是 Closest distance between countries,但它使用的包“maps”似乎不再起作用。
library(maps)
library(geosphere)
library(dplyr)
world.map <- map(database = "world", fill = TRUE)
导致的错误:
as_mapper(.f, ...) 中的错误:缺少参数“.f”,没有默认值
此外,我还找到了包裹 cepiigeodist
知道如何修复此代码吗?或者知道将执行此任务的另一个包?
谢谢
答案 0 :(得分:0)
也许这是一个解决方案的角度
library( rnaturalearth )
library( rnaturalearthdata )
library( sf )
ne_countries(scale = "medium", returnclass = "sf" ) %>%
slice(1:5) %>% #only for first five countries
st_distance( )
# Units: [m]
# [,1] [,2] [,3] [,4] [,5]
# [1,] 0.0 12619446 9261566 958640.6 9022851
# [2,] 12619445.9 0 5860718 11647165.5 3538828
# [3,] 9261566.5 5860718 0 8615776.8 4938544
# [4,] 958640.6 11647165 8615777 0.0 8042914
# [5,] 9022851.4 3538828 4938544 8042913.9 0