-1

I have a series of tracking data in the form of coordinates from individuals leaving and returning to the same place (ie. all of them leaving from the same coordinates) and would like to find the maximum Euclidean distance reached from the starting point for each individual, my data set looks more or less like this

   LON      LAT      ID year    
-5.473959 51.72998   1  2010    
-5.502444 51.58304   1  2010  
-5.341897 50.97509   1  2010    
-5.401117 50.76360   1  2010 

and the coordinates of the starting point are x=-5.479,y=51.721

ID represents each individual (only shown ID 1 as data set extremely long), where I have more than 100 individuals per year and 8 years of data.

Any help is appreciated!

Prasanna S
  • 353
  • 1
  • 10

1 Answers1

1

Here's an approach with dplyr and distHaversine:

library(dplyr)
library(geosphere)
data %>% 
  mutate(distance = distHaversine(c(-5.479,51.721), cbind(LON, LAT))) %>%
  group_by(ID) %>%
  summarize(max = max(distance, na.rm = TRUE))
# A tibble: 1 x 2
     ID     max
  <int>   <dbl>
1     1 106715.

The output should be in meters.

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57