Skip to content
Prev 9382 / 29559 Next

questions on RasterStack/Brick

On Tue, Sep 21, 2010 at 12:49 AM, Martin <martin_brandt at gmx.net> wrote:
You can use what Nikhil send you or perhaps (for objects that are not
too big), with RasterStack s

x <- as(s, 'SpatialGridDataFrame')
x <- flipVertical(x)
s2 <- stack(x)  # or   b <- brick(x)

or get raster 1.5.9 from R-Forge in a couple of hours and then do

x <- flip(s, direction='y')
You can do things like this:

myfun = function(v, ...) { d <- data.frame(x=1:length(v), y=v);
lm(y~x, data=d)$coefficients[2] }

a <- calc(stack, fun=myfun)
Not directly, I think, but if you have two stacks, s1, and s2, and
some patience, you can do:

 r <- raster(s1)
for (i in 1:ncell(r)) {
    r[i] <- cor(as.vector(cellValues(s1, i)), as.vector(cellValues(s2, i)))
}


Robert