【发布时间】:2020-02-09 21:35:01
【问题描述】:
我有这个数据框individual_dets,其中包含一些经纬度值。这是数据框
individual_dets = structure(list(location = c("ARB-04", "BIRCHY HEAD", "Boca1",
"BON-AR-S2", "BON-AR-S2", "BON-W-S5"), month = structure(c(12L,
10L, 10L, 8L, 11L, 2L), .Label = c("Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), class = c("ordered",
"factor")), year = c(2018, 2018, 2018, 2018, 2018, 2018), detection_count = c(3L,
256L, 2L, 4L, 2L, 2L), num_unique_tags = c(1L, 1L, 1L, 1L, 1L,
1L), total_res_time_in_seconds = c(0, 1182040, 0, 2732221, 0,
0), latitude = c(24.94808, 44.5713, 26.32559, -49.27732, -49.27732,
-49.27985), longitude = c(-80.45412, -64.03512, -80.07108, 69.48038,
69.48038, 69.47853)), class = c("grouped_df", "tbl_df", "tbl",
"data.frame"), row.names = c(NA, -6L), groups = structure(list(
location = c("ARB-04", "BIRCHY HEAD", "Boca1", "BON-AR-S2",
"BON-AR-S2", "BON-W-S5"), month = structure(c(12L, 10L, 10L,
8L, 11L, 2L), .Label = c("Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"), class = c("ordered",
"factor")), .rows = list(1L, 2L, 3L, 4L, 5L, 6L)), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE))
但是,我的数据框有 4247 个观察值。
纬度和经度值适用于大西洋西北部的大洋坐标。我正在尝试计算这些经纬度值与哈利法克斯的距离。
有人告诉我使用此功能snap points to line,然后使用lappy,但我正在查看结构,我很迷茫。有谁知道如何使用函数snap points to line 和 lappy 进行编码以获得近似距离?
【问题讨论】:
-
snap points to line在什么包中?这不是 r 中的有效函数名称,因为它包含空格。我确实在maptools中找到了snapPointsToLines,但它特别警告“此功能不适用于地理坐标。” -
好吧,那是我被建议的……我没注意到。这可能就是为什么它对我不起作用。你知道我可以使用的其他功能吗?
标签: r coordinates distance