![](/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.