I currently have a column of coordinates(CHR) and longitude & latitude(NUM). I want to create a function that allows to find the distance between each two coordinates. like distance between 1st and 2nd coord, 2nd and 3rd, an so on. I have tried both way to create it.
data$new.Distance[2:n] <- distm(data$Coord[1:(n-1)], data$Coord[2:n], fun = distMeeus)
data$new.Distance[2:n] <- distm(
c(data$longitude[1:(n-1)], data$latitude[1:(n-1)]),
c(data$longitude[2:n], data$latitude[2:n]),
fun = distMeeus
)
and I got error message:
ERROR in N-1: non-numeric argument to binary operator.
How should I fix that? or is there any other way to create this in R? Thank you.