This is my data in a matrix. It is lat and long. I want the distance between point 1 and 2, 2 and 3, 3 and 4, etc.
> mat<-as.matrix(b)
> mat
buoy.LON buoy.LAT
[1,] -86.34816 43.19014
[2,] -86.34337 43.18656
[3,] -86.34013 43.18268
[4,] -86.33468 43.17484
[5,] -86.33091 43.16549
[6,] -86.32912 43.15925
[7,] -86.32786 43.14887
dis<-distGeo(mat[2,],mat[3,]) #distance in meters
did
[1] 505.1605
The above formula works great, but I want to make a loop to do this quickly and I want the data to be added to the matrix.
I created this loop
for (i in mat[1:169,]) {
distGeo(mat[i,], mat[i+1,])
}
but I always get a return of
196
How can I get the for loop to work correctly, and how can I get the answers added to the matrix?