【发布时间】:2020-02-01 09:21:35
【问题描述】:
假设我有以下两个数据框
dfA <- data.frame(x = rpois(10,2), y = rpois(10,2), z = rpois(10,2), q = rpois(10,2), t = rpois(10,2))
dfB <- data.frame(x = rpois(10,2), y = rpois(10,2), z = rpois(10,2), q = rpois(10,2), t = rpois(10,2))
dfAB <- map2_df(dfA, dfB, str_c, sep=",") %>%
rename_all(~ str_c('C', seq_along(.)))
dfC <- data.frame(x = rpois(10,2), y = rpois(10,2), z = rpois(10,2), q = rpois(10,2), t = rpois(10,2))
dfD <- data.frame(x = rpois(10,2), y = rpois(10,2), z = rpois(10,2), q = rpois(10,2), t = rpois(10,2))
dfCD <- map2_df(dfC, dfD, str_c, sep=",") %>%
rename_all(~ str_c('C', seq_along(.)))
我要查找的是第一个数据帧和第二个数据帧中的坐标之间的距离,所以我得到了第三个数据帧,其中包含 dfAB 的第一个单元格和 dfCD 的第一个单元格之间的距离,以及第二个数据帧之间的距离dfAB 的单元格和 dfCD 的第 2 个单元格等;即调用列C和行R,我想要之间的距离
dfAB and dfCD
C1 C2 C... C1 C2 C...
R1 R1 R1 R1
R2 R2 R2 R2
... ... ... ...
etc
我要找的是dfABC1R1和dfCDC1R1、dfABC1R2和dfCDC1R2、dfABC2R1和dfCDC2R1等之间的距离。
当我尝试使用时
dist(dfAB,dfCD)
我收到错误:dist(dfAB,dfCD) 中的错误:距离方法无效
非常感谢任何帮助
【问题讨论】:
标签: r coordinates distance