0

I have a data frame (locations_54) of columns with latitude and longitude values. I know there is the geosphere package in R, so, I wanted to use distHaversine() to get distance between two points with latitude and longitude.

Here is what I have. I'm not sure what is going wrong here.

d_1 <- c()
d_2 <- c()
d_1[i] <- c(locations_54[["longitude"]][i], locations_54[["latitude"]][i])
d_2[i] <- c(locations_54[["longitude"]][i+1], locations_54[["latitude"]][i+1])

distance <- c()
for (i in 1:(nrow(locations_54)-1)) {
  distance[i] <- distHaversine(d_1, d_2)
}
www
  • 38,575
  • 12
  • 48
  • 84
  • Just from looking, there appears to be quite a lot wrong with your code. Can you add the output of `dput(head(locations_54))` to your question. – SymbolixAU Jul 12 '17 at 00:22
  • @SymbolixAU I've solved this! thanks. –  Jul 12 '17 at 04:06
  • @SymbolixAU Now, my new problem: https://stackoverflow.com/questions/45048231/r-timestamp-with-iteration-for-machine-learning-30-minute-window –  Jul 12 '17 at 04:06

0 Answers0