Say I have a dataframe such as this:
d<-data.frame(x=c(400.4,400.2,400.1,394.3,396.5),
y=c(330.2,330.2,330.1,289.9,288.8))
I can calculate the Euclidian distance for the first two rows like this:
dist(d[1:2,]) #0.2
If I wish to do this for every successive row, e.g. distance between rows 1&2, 2&3, 3&4 etc. I have written a for loop, but this is incredibly slow with thousands of rows. Is there a more efficient way of doing this?