-1

I am trying to measure the geographic and language distance between all countries and the United States (e.g. the distance between Canada and the USA, Iran and USA, and etc).

The data is available via http://www.cepii.fr/pdf_pub/wp/2011/wp2011-25.pdf but I am unsure how to actually calculate the distance with the long/lat info, and the language info.

Thanks!

Edited to add photo: I want to create a 4th variable that shows the distance between each country and the USA (38.8670000, -77.0000000). Example of data I know the distHaversine gives allows me to do this one by one, but how can I use the distHaversine to compute this for all the countries in my dataset (each country's distance to the US)

I tried this: mutate(geo, Distance = distHaversine(cbind(lon, lat), c(38.8670000, -77.0000000))) but it returns incorrect distances.

SaraFormula
  • 61
  • 1
  • 6
  • For lat/long distance, have you tried using `geosphere::distHaversine` (or one of the package other distance functions)? For distance between languages, you will need to be more specific ... do you mean that the "distance" between Spanish and Chinese is 4, and American English to British English is 0.3? StackOverflow really isn't a good *research* site, it's mostly about helping with *code*. Do you have any that is misbehaving? – r2evans Aug 17 '20 at 00:17

1 Answers1

0

Figured it out!

myLong <- -77.0000000
myLat <-38.8670000

geo1 %>%  mutate(dist = distHaversine(cbind(myLong, myLat), cbind(lon, lat)))
SaraFormula
  • 61
  • 1
  • 6