I am building a function (for the first time). I am attempting to use earth.dist to calculate the farthest distance between 2 points for each animal-month. I have been fiddling with the codes for about 4 hours and cannot figure out why I am getting identical values for each animal-month (I tested it out on a single animal-month and it worked nicely). Hopefully someone can point me in the correct direction in terms of applying the function to each animal-month. Thanks.
There are essentially 3 columns, animal-month (unique animal ID concatenated with the month), lat and long.
maxdist<- function(latlong, latlongt,a2,dt,farth)
{
latlong<-movementfile[c(18,17)] #cols indicating long/lat
latlongt<-data.table(latlong)
a2<-earth.dist(latlongt, FALSE)
dt<-as.data.frame(as.table(a2))
farth<-max(dt$Freq)
}
lapply(unique(movementfile$animal_month),maxdist)