I have the dataframe below and I would like to subset it in a way that it should find the observation when a name
covered the longest distance between two consecutive observations. If there is a situation when a name
moves exactly the same amount of meters at the same time to select the most recent.
So I would like to have as final result 2 rows. Those consequtives with the longest distance, And if there are more than one consequtive pairs only the most recent should remain. Then I will take those 2 points and I will display them on a map.
Here is my data:
name<-c("bal","bal","bal","bal","bal","bal","bal","bal")
LAT<-c(54.77127,54.76542,54.76007,54.75468,54.74926 ,54.74385,54.73847,54.73228)
LON<-c(18.99692,18.99361,18.99059 ,18.98753,18.98447,18.98150,18.97842,18.97505 )
dtime<-c("2016-12-16 02:37:02","2016-12-16 02:38:02","2016-12-16 02:38:32","2016-12-16 02:39:08",
"2016-12-16 02:39:52","2016-12-16 02:41:02","2016-12-16 02:42:02","2016-12-16 02:42:32")
df<-data.frame(name,LAT,LON,dtime)
anf this is how I think I should calculate the distance
library(geosphere)
distm(c(as.numeric(df[1,3]),as.numeric(df[1,2])), c(as.numeric(df[2,3]),as.numeric(df[2,2])), fun = distHaversine)
and this regarding time difference:
difftime("2016-12-19 11:33:01", "2016-12-19 11:31:01", units = "secs")
but how can I combine them?