[R-sig-Geo] melt spatialPixelDataFrame

Michael Sumner mdsumner at gmail.com
Wed Jul 18 15:22:54 CEST 2012


On Wed, Jul 18, 2012 at 11:16 PM, Johannes Radinger <JRadinger at gmx.at> wrote:
> Hi,
>
> maybe someone know a simple solution:
>
> I want to melt (melt from reshape2) a SpatialPixelDataFrame with the two ids (x and y).
>
> I tried:
> 1) to transform the SPDF to a normal dataframe with as.data.frame(spdf) but then I loose my x and y columns. Thus I can't use them in melt. Was that behavior changed recently?

No, I really don't think so. Are you sure?  Here x.1 and y.1 are the
(re-attached) grid point coordinates, which incidentally are copies of
the original data "x" and "y".

data(meuse.grid)
m = SpatialPixelsDataFrame(points = meuse.grid[c("x", "y")], data = meuse.grid)
head(as.data.frame(m))
       x      y part.a part.b      dist soil ffreq    x.1    y.1
1 181180 333740      1      0 0.0000000    1     1 181180 333740
2 181140 333700      1      0 0.0000000    1     1 181140 333700
3 181180 333700      1      0 0.0122243    1     1 181180 333700



> 2) to melt the spdf itself wasn't working either....
>
> Probably I need a normal dataframe + the x and y column from the SPDF.
>
> /Johannes
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



-- 
Michael Sumner
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-sig-Geo mailing list