Your plgn
is a SpatialPolygonsDataFrame
, and as such, is.na(over(d, plgn))
returns a logical matrix. This cannot be used to subset your SpatialPoints*
. You can do the following to convert the logical matrix to a vector that the subsetting operation can accommodate:
d[complete.cases(over(d, plgn)), ]