Everyone. I'm trying to filter GPS location data based on distance (UTMs) and time (H:M:S) criteria independently and concurrently. Here's the data structure:

```
head(collar)
FID  animal      date       time        zone easting northing
1    URAM01_2012 6/24/2012  10:00:00 AM 13S  356664  3971340
2    URAM01_2012 6/24/2012  1:02:00 PM  13S  356760  3971480
3    URAM01_2012 6/24/2012  4:01:00 PM  13S  357482  3972325
4    URAM01_2012 6/24/2012  7:01:00 PM  13S  356882  3971327
5    URAM01_2012 6/25/2012  4:01:00 AM  13S  356574  3971765
6    URAM01_2012 6/25/2012  7:01:00 AM  13S  357796  3972231

```

Right now I'm filtering by distance only but I'm having some issues. The code should calculate the distance between FID[1] and FID[2] and then assign that distance to FID[1] in a new column ($step.length). After all distances have been calculated, the data is then subsetted based on a distance rule. Right now I have it set to where I want all locations that are >200m apart. Once subsetted, the process is then repeated until the distance between all subsequent locations is >200m. Here's the code that I've written that accomplishes only a portion of what I'd like to do:

```
reps <- 10
 #Begin loop for the number of reps. Right now it's at 10 just to see if the code works.
for(rep in 1:reps){

  #Begin loop for the number of GPS locations in the file
  for(i in 1:length(collar$FID)){

    #Calculate the distance between a GPS location and the next GPS locations. the formula is the hypotenuse of the Pythagorean theorem. 
    collar$step.length[i] <- sqrt(((collar$easting[i] - collar$easting[i+1])^2) + ((collar$northing[i] - collar$northing[i+1])^2))

  }

  #Subset the data. Select all locations that are >200m from the next GPS location.
  collar <- subset(collar, step.length >200) 

}

```

Now, the code isn't perfect and I would like to add 2 conditions into the code. 

1.) Animal ID isn't considered. Therefore, a distance for the last location of an animal will be generated using the first location of a new animal when the distance should be NA. I thought using for(i in 1:unique(collar$animal)) might work, but it didn't (shocking) and I'm not sure what to do since for(i in length(collar$animal)) doesn't use only unique values.

2.) I'd also like to insert a break in the for loop when all locations that are >200m. I'm sure there has to be a better way of doing this, but I thought I'd set reps to something large (e.g., 10000) and once a criteria was met then R would break:

```
if(collar$step.length > 200){
   break }

```

Yet, since the if condition is >1 only the first element is used. I've haven't thought about time or distance/time yet, but if anyone has any suggestions for those endeavors, I'd appreciate the advice. Thanks for your help and guidance.