代码参考https://www.r-bloggers.com/2019/10/geographic-distance/
library(maps)
library(sf)
library(tidyverse)
library(units)
library(rnaturalearth)
cities1 <- st_as_sf(world.cities, coords = c("long", "lat"), crs = 4326)
china<-filter(cities1)
capitals <- filter(cities1, capital == 1)
capitals <- mutate(capitals, city_country = str_c(name, " (", country.etc, ")"))
dist_amsterdam <- st_distance(slice(capitals),
slice(capitals))
结果是值,但不是数据框。我需要的是一个具有country.ect
列和行的数据框。
country.ect Jordan United ArbEmirates ...
Jordan dist_amsterdam result
United ArbEmirates
...
1条答案
按热度按时间6bc51xsx1#
如果我正确地理解了你的目标,即一个完整的表,每个大写字母之间的所有距离,下面应该会导致预期的结果。
创建于2023-04-22使用reprex v2.0.2