【问题标题】:find maximum distance between a series of coordinates of different individuals to a single point找到不同个体的一系列坐标到单个点之间的最大距离
【发布时间】:2020-10-07 21:36:48
【问题描述】:

我有一系列以坐标形式的跟踪数据,来自个人离开和返回同一个地方(即他们都从同一个坐标离开),我想找到从起点到达的最大欧几里得距离对于每个人,我的数据集看起来或多或少是这样的

   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 年的数据。

感谢任何帮助!

【问题讨论】:

    标签: r euclidean-distance


    【解决方案1】:

    这是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.
    

    输出应该以米为单位。

    【讨论】:

    • 太棒了,应用到整个数据集非常简单,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-06
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 2020-02-12
    • 2022-11-02
    • 1970-01-01
    相关资源
    最近更新 更多