【发布时间】:2017-09-14 00:43:37
【问题描述】:
我有一个数据框(称为 coors),其中包含一个 x 坐标向量和一个 y 坐标向量。
我有另一个数据框(称为pickPoint),其中包含感兴趣的指定(x,y)对。
目标是将每个coors 点与其最近的pickPoint 相关联。我想使用Euclidean norm (l-2)。如果可能的话,请您整理好方法。
Coor = data.frame(row = rep(1:96, each = 72),
col = rep(1:72, times = 96))
PickedPoint = data.frame(ppRow = sample(96,10),
ppCol = sample(72,10))
还有一个类似的帖子,不过是用python发的:
How to find the closest (x, y) position to (x,y) position in another list?
到目前为止,我已经为答案提供了一个基准:
microbenchmark(CPak(), latemail(),Jul(), times=10L)
Unit: milliseconds
expr min lq mean median uq max neval
CPak() 37.83691 38.60585 43.66030 39.86094 44.9592 62.784 10
latemail() 4275.10 4536.783 4674.966 4712.938 4855.860 5045.069 10
Jul() 37.38809 39.87625 46.17202 44.90693 53.08938 57.33 10
【问题讨论】:
标签: r dataframe coordinates computational-geometry tidyverse