2
A
回答
2
下面是解决这个问题的方法之一。
library(raster)
library(sp)
### create some example datasets
coords_A = cbind(runif(10, 1, 10), runif(10,1,10))
sp_A = SpatialPoints(coords_A)
spdf_A = SpatialPointsDataFrame(coords_A, data.frame(varA=letters[1:10]))
coords_B = cbind(runif(10, 1, 10), runif(10,1,10))
sp_B = SpatialPoints(coords_B)
spdf_B = SpatialPointsDataFrame(coords_B, data.frame(varB=letters[11:20], varC=LETTERS[11:20]))
### compute the complete distance matrix between the two sets of points
dist_mat <- pointDistance(spdf_A, spdf_B, lonlat = FALSE, allpairs = TRUE)
### identify nearest point in dataset B for every point in dataset A
nearest <- apply(dist_mat, 1, which.min)
### bind together the data from the dataset B (in your case the "red points")
### at the closest point to dataset A ("black points")
[email protected]<- cbind([email protected], [email protected][nearest,])
+0
你的模拟例子像一个魅力工作,谢谢! –
相关问题
- 1. 如何使用R中的坐标映射常规数据集?
- 2. R-如何翻转空间点数据框的坐标
- 3. 使用R合并两个数据集
- 4. R - 合并并更新主数据集
- 5. 合并R中的相邻区域(聚合空间数据)?
- 6. 在R中合并大数据集并标记不匹配
- 7. 如何使用Ruby集合函数从空行合并值?
- 8. 合并R中的两个数据集
- 9. 合并两个数据集中的R
- 10. R,合并数据集更改键值
- 11. R + GGPLOT2 - 集合数据由区间
- 12. 使用D3D绘制骨架数据:坐标空间转换
- 13. 器R并联的foreach空间数据
- 14. GLSL坐标空间?
- 15. 如何将三维空间坐标转换为二维空间坐标?
- 16. 用于空间坐标的3D数组
- 17. 如何合并R 3中数据帧
- 18. 如何合并两个数据帧R
- 19. R:数据框 - 如何合并值并合并重复值?
- 20. 在MapInfo或QGIS中合并两个地理空间数据集
- 21. 使用联合()后从tplyr R空间
- 22. 集合中的Numpy数组坐标
- 23. 使用sparkR合并大数据集
- 24. 使用AWK合并两个数据集
- 25. 如何在R中绘制和制作坐标(经度/纬度)坐标数据?
- 26. 如何合并r中数据框中的列标题
- 27. 用标签绘制空间坐标
- 28. 使用R将数据集中的空白空间重新编码为NA
- 29. R中的坐标坐标
- 30. R绘图坐标轴不符合,数据超出它们
这是一个关于空间数据集的普通R编程问题 - 答案在我看来非常好 - 应该发布给大家来欣赏。我无法在任何其他论坛找到这个问题的答案。 –