One way to do this is to filter the rows from the data that don't match what you want. If I'm correct about the distanceTrack function, it takes N lat / lon points and reduces them to N-1 distances between those points. You then only need to eliminate the points that aren't ten minutes apart, which you can do pretty easily by filtering the dataframe.
Not knowing what exactly your data looks like, I've created some example data below that hopefully resembles it:
## Create a data.frame of 10-minute intervals stored as POSIXct
## You can convert most times to POSIXct using as.POSIXct if they are not already that format
lizard <- data.frame(time=seq(from=as.POSIXct('2015-01-01 00:00:00'), to=as.POSIXct('2015-01-02 00:00:00'), by=10*60))
## Randomly eliminate rows with probability of 15% that a given row is eliminated to create gaps
lizard$keep = runif(nrow(lizard))
lizard <- lizard[lizard$keep <= .85, c('time'), drop=FALSE] ## drop arg used to kepe it a dataframe
## Random lat / lon data:
lizard$Lat = runif(nrow(lizard)) ## runif is random uniform
lizard$Lon = runif(nrow(lizard))
Now I run the distance calculation. We need to run the distance calculation before eliminating the rows, because even if there is a time gap between rows i
and j
(i.e., j$time
- i$time
> 10 minutes), we still need the values from row j
to calculate the distance traveled between rows j
and k
, which may themselves be 10 minutes apart:
## We initialize to NA; the distance variable for row i will represent the distance between row i-1 and i;
## row 1 will not have a meaningful value
lizard$distance <- NA
lizard$distance[2:nrow(lizard)] <- distanceTrack(lizard$Lat, lizard$Lon)
And finally we can use a boolean to filter the rows by comparing rows i and i-1 for each row 2:N:
lizard$isContiguous <- TRUE ## initialize a variable to determine if the data is at 10-min interval
lizard$isContiguous[2:nrow(lizard)] <- (as.numeric(lizard$time[2:nrow(lizard)] - lizard$time[1:nrow(lizard) - 1]) == 10)
lizard <- lizard[lizard$isContiguous, ] ## filter
The distances left in that dataframe are only the ones for which the time interval was 10 minutes.
For more information on filtering (or more precisely, extracting or replacing), check out the documentation here:
For [-indexing only: i, j, ... can be logical vectors, indicating elements/slices to select