[英]find maximum distance between a series of coordinates of different individuals to a single point
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起点坐标为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. ID 代表每个人(仅显示 ID 1 为极长的数据集),其中我每年有超过 100 个人和 8 年的数据。
Any help is appreciated!任何帮助表示赞赏!
Here's an approach with dplyr
and distHaversine
:这是
dplyr
和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. output 应以米为单位。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.