Skip to content
Prev 6527 / 29559 Next

unexpected behaviour of subset.SpatialPointsDataFrame()

Yes, and if you do a

names(as.data.frame(meuse.grid))

after your example, there's even more duplication. What happens is that

coordinates(meuse.grid) <- ~x+y

takes x and y out of the data frame and moves them to the coordinates.
The motivation for this was limiting the object size and memory usage.
An alternative creator,

coordinates(meuse.grid) <- meuse.grid[c("x", "y")]

duplicates them, as it wouldn't know what to move. subset does the same
duplication, more as a side effect then intentional.

It is hard to say what would be the right way; e.g. meuse.grid$x does
not work using the first creation method, but works using the second, or
your subset. As an alternative you might consider

meuse.grid[meuse.grid$dist > 0.01,]

which does not duplicate.
--
Edzer
Tom Gottfried wrote: