[R-sig-Geo] unexpected behaviour of subset.SpatialPointsDataFrame()

Edzer Pebesma edzer.pebesma at uni-muenster.de
Wed Sep 23 21:12:29 CEST 2009


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:
> Hi Edzer, Roger and list,
>
> is it intended that subset.SpatialPointsDataFrame() returns two additional columns with the
> coordinates in the data-slot of it's return value?
>
> data(meuse.grid)
> names(meuse.grid)
> coordinates(meuse.grid) <- ~x+y
> names(meuse.grid)
> meuse.grid <- subset(meuse.grid, meuse.grid$dist > 0.01)
> names(meuse.grid)
>
> Regards,
> Tom
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>   

-- 
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de/
http://www.springer.com/978-0-387-78170-9 e.pebesma at wwu.de



More information about the R-sig-Geo mailing list