I'm trying to measure the difference between locations, without repetition.
I have a dataframe with citynames and lon + lat columns. The distance should be measured between city1 and city2, city1 and city3, etc. Until city n-1 and city n.
My tries have been varied, but the latest was:
i <- 1
j <- 2
while (i < 51){
while (j < 50){
setDT(df)
df[, distance_hav := distHaversine(matrix(c(df$lon[i]
, df$lat[i]
, ncol = 2)
, matrix(c(df$lon[j]
, df$lat[j]
, ncol = 2))]
j <- j + 1
}
i <- i + 1
}
Any help is much appreciated.