[R] Calculate geographic/euclidian distance between consecutive XY-pairs

Johannes Radinger johannesradinger at gmail.com
Tue Dec 18 10:56:57 CET 2012


Hi,

I have a dataframe containing 3 columns:

data.frame(X=c(100,102,104,102,103),Y=c(12,14,14,13,16),Time=c(1,2,3,4,5))

where X and Y are coordinates and "Time" refers to an index of a timestep.
Now I would like to get the distance between the consecutive timesteps.

This should actually provide a vector of length=4, representing the euclidian
resp. geopgraphic distance between the first and the second, and the second
and the third timestep and so on...

Is there a simple way to calculate this and get the resulting vector
as a result?
Or can anyone give an example?


best regards,
/j



More information about the R-help mailing list