[R-sig-Geo] creating rasterStack from a matrix
Robert J. Hijmans
r.hijmans at gmail.com
Sat Jul 10 05:35:51 CEST 2010
Not that I can think of. Something for the to-do list.
Below is how you could make a RasterBrick (which should be preferable
to a RasterStack for objects created in memory (and otherwise their
behavior is similar to a RasterStack).
id <- data.frame(cell=1:ncell(globe))
idv = merge(id, stackmatrix, by=1, all.x=T)
globe <- setValues(globe, as.matrix(idv))
On Fri, Jul 9, 2010 at 3:21 PM, steven mosher <moshersteven at gmail.com> wrote:
> Assuming I have a matrix of Nrows and Mcols where
> Column #1 is filled with a valid cell number for a raster. ALL cell numbers
> will not
> be present.
> Subsequent columns (2-M) contain the data that I want to place in a sequence
> layers, so that in the end I have a rasterStack of M layers. M can be quite
> ( like 1000-2000) Essentially they are values at various time slices where
> is M.
> In any case, if there is only one layer ( column 2) then assigning the
> values in column
> 2 to the cells in column 1 is straightforwd (assuming I read the manual
> That works like this:
> ( Create a dummy version of the data with 200 cells)
> # fake values
> # toss some valid cell numbers in column 1
> globe<-raster(nrows=36, ncols=72, xmn=-180, xmx=180, ymn=-90, ymx=90,
> + projs="+proj=longlat +datum=WGS84")
> # assign the values in column 2 to the cells in column 1.
> If I have a large number of columns and I want to create a large rasterStack
> with all the data, is there a slick way to do it
> Perhaps apply?
> [[alternative HTML version deleted]]
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
More information about the R-sig-Geo