[R-sig-Geo] Creating a data frame from a set of rasters that includes XY values as columns

Damian Maddalena damianmaddalena at gmail.com
Tue Feb 24 18:19:54 CET 2015


Hello.

I am trying to create a data frame from a series of rasters that 
includes a column for each raster and a column for the corresponding XY 
values. IE: I want each row to be the cell values at every XY location.

For example, if I pull down the worldclim bioclim data (below), I would 
like to unpack one or more rasters from the raster stack and assemble 
them as a data frame with X and Y as an attribute. IE: I want a data 
frame where each record is a cell, and the attributes are X,Y,Z1...Zx.

 > library(raster)
 > d <- getData('worldclim', var='bio', res=10)

I have done this in GRASS with all data imported but I would like to try 
to do it in R in the most succinct way possible. I am getting tripped up 
on the structure of the raster stack.

Any hints on how to proceed would be appreciated. Should I just pull out 
the raster values, turn them into a vector, slap them into a data frame, 
then append the range for the XY? Would that line up correctly?

Thank you.

-Damian

-- 
“Science knows it doesn't know everything; otherwise, it'd stop. But just because science doesn't know everything doesn't mean you can fill in the gaps with whatever fairy tale most appeals to you.” ~Dara Ó Briain



More information about the R-sig-Geo mailing list