adkane
adkane

Reputation: 1441

How to calculate the distance between coordinate data by date?

My data is of the form:

* date        lat      long
* 01/01/13    47        118
* 01/01/13    48        119
* 01/01/13    47        118
* 02/01/13    46        119
* 02/01/13    46        119
* 02/01/13    48        118

I want to be able to calculate the distances between the points by date e.g. for 01/01/13, how far it is from the first row to the second and then from the second to the third etc. My actual data has more than 3 points per date.

The function

earth.dist(lats, dist = TRUE) 

does this but will calculate the distances between dates as well. Any ideas? Thanks.

Upvotes: 1

Views: 358

Answers (1)

Ricardo Saporta
Ricardo Saporta

Reputation: 55340

library(data.table)
DT <- as.data.table(YourDataFrame)

DT[, earth.dist(c(lat, long)), by=date]

Upvotes: 2

Related Questions