In R, I need to calculate the grand mean of distance between all the relocations of the same individual.
I have a dataset similar to this:
individual<- c(a,b,a,b,a,c,a,b) x<-c(167685,167945,167685,153985,167685,158675,167645,167667) y<-c(9876548,9879248,9876838,9596548,9926548,9878578,9876548,9166548)
In which each "individual" represents a different animal, and x/y points represent locations where the animals were observed. Some individuals were relocated many times, while other individuals were only relocated once.
I'd need to calculate the mean distance between every observation and all the other observations of the same animal, iterating the process for every observation of the animal. Finally these distances should be averaged by getting a single value of "spread of relocations" for each individual. The animals which were observed only once should get "NA" in this variable.
In the output table, each row would summarize the spread of recaptures of an individual, like so:
individual spread a 34 b 56 c NA