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. 如何使用Ruby集合函数从空行合并值?
- 4. R,合并数据集更改键值
- 5. 合并R中的两个数据集
- 6. R + GGPLOT2 - 集合数据由区间
- 7. 使用D3D绘制骨架数据:坐标空间转换
- 8. GLSL坐标空间?
- 9. 器R并联的foreach空间数据
- 10. 如何将三维空间坐标转换为二维空间坐标?
- 11. 如何合并两个数据帧R
- 12. R:数据框 - 如何合并值并合并重复值?
- 13. 使用联合()后从tplyr R空间
- 14. 使用R将数据集中的空白空间重新编码为NA
- 15. R坐标位保存到数据帧
- 16. 使用时间戳合并两个数据集
- 17. 如何合并重复数据集值到单个数据集
- 18. 子集数据按R中的间隔集合
- 19. 如何合并旧数据以节省Elasticsearch空间
- 20. 如何合并数据时间
- 21. R有空隙的极坐标图段
- 22. 如何使用yield返回空集合?
- 23. 获取xarray的非nan值的坐标数据集数据集
- 24. 使用合并在R中组合列表数据?
- 25. R - 如何在空间多边形框架对象中显示插槽“坐标”中的数据
- 26. 如何使用命名空间系统:集合
- 27. 如何根据坐标过滤数据?
- 28. 转换目标坐标空间
- 29. 合并SAS数据集
- 30. 如何使用JavaScript和此坐标格式生成多维数据集?
这是一个关于空间数据集的普通R编程问题 - 答案在我看来非常好 - 应该发布给大家来欣赏。我无法在任何其他论坛找到这个问题的答案。 –