I have a dataset with info on international investments in Europe and coordinates about NUTS3. For each investment I have the city and the coordinates (lat1,long1). I want to compute the distance from each city to each of the NUTS 3 I have --> E.G. Paris to Paris, Paris_Lyone, Paris_Orly, Paris_Maidenhead etc etc. I want to loop this mechanism for all the cities I have, so at the end I have a matrix for each city that include its distance to each NUTS. I tried to use geosphere but it gives me just the distance between rows.
summary(coordinate$NUTS_BN_ID)
summary(fdimkt$NUTS_BN_ID)
##merge dataset
df <- merge(fdimkt,coordinate, by="nutscode", all = FALSE)
View(df)
fix(df)
#install.packages("dplyr")
library(dplyr)
df %>% dplyr::rename(lat1= `_destination_latitude`, long1= `_destination_longitude` )
library(geosphere)
library(data.table)
#dt <- expand.grid.df(df,df)
setDT(df)[ , dist_km := distGeo(matrix(c(`_destination_latitude`, `_destination_longitude`), ncol = 2),
matrix(c(`lat2`, `long2`), ncol = 2))/1000]
summary(df$dist_km)
This didn't work because it returns me the distance by row, but I actually want the distance from each city to all the NUTS3 coordinates I have
Someone can help me with this?
I'm not sure on how to post my dt, this I gues that might help to have more suggestions.