R根据属性删除重复的空间点

del*_*aye 3 r rgdal r-sp

在RI中有一个SpatialPointsDataFrame whit复制点(坐标和属性),我想用相同的数据删除所有点...

我在sp包中找到了这个remove.duplicates()函数,但它似乎只在位置上删除了...还有另一种方法吗?

谢谢

E.

joh*_*nes 7

会这样的吗?

library(sp)
pts <- SpatialPoints(cbind(c(1, 1, 1, 2, 3, 4), c(1, 1, 1, 4, 2, 4)))
pts <- SpatialPointsDataFrame(pts, data=data.frame(id = c(1, 2, 2, 3, 4, 5)))

## All points
pts

## No spatial duplicates
remove.duplicates(pts)

## No duplicates in attributes
pts[which(!duplicated(pts$id)), ]

## Combination
pts[which(!duplicated(as.data.frame(pts))), ]
Run Code Online (Sandbox Code Playgroud)