In the next step, we filter by the capital cities encoded in the column capital with 1.
![compute geodist for each row compute geodist for each row](https://macrordinary.ca/wp-content/uploads/2019/11/image-65.png)
# proj4string: +proj=longlat +datum=WGS84 +no_defs # Simple feature collection with 43645 features and 4 fields # convert the points into an sf object with CRS WSG84Ĭities <- st_as_sf(world.cities, coords = c("long", "lat"), crs = 4326) To convert points with longitude and latitude into a spatial object of class sf, we use the function st_as_sf(), indicating the coordinate columns and the coordinate reference system (WSG84, epsg: 4326).
![compute geodist for each row compute geodist for each row](https://i.ytimg.com/vi/ABY5rYu3Rmc/maxresdefault.jpg)
Head(world.cities) # from the maps package We will use the capital cities of the whole world with the objective of calculating the distance to the nearest capital city and indicating the name/country.