![](/img/trans.png)
[英]Calculate the distance between two coordinates columns group by individuals of different ID length in R
[英]find maximum distance between a series of coordinates of different individuals to a single point
我有一系列以坐标形式的跟踪数据,来自个人离开和返回同一个地方(即他们都从同一个坐标离开),并希望找到每个人从起点到达的最大欧几里得距离,我的数据集看起来或多或少是这样的
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
起点坐标为x=-5.479,y=51.721
ID 代表每个人(仅显示 ID 1 为极长的数据集),其中我每年有超过 100 个人和 8 年的数据。
任何帮助表示赞赏!
这是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.
output 应以米为单位。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.