[R-sig-Geo] questions on RasterStack/Brick

Robert J. Hijmans r.hijmans at gmail.com
Tue Sep 21 21:48:46 CEST 2010


On Tue, Sep 21, 2010 at 12:49 AM, Martin <martin_brandt at gmx.net> wrote:
>
> Dear all,
>
> I have some questions concerning stacks and bricks from the raster package.
>
> 1. is it possible to flip the whole stack vertically? I get an error when I
> use the 'flip' function..
>

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')


> 2. is it possible to use the calc function (or something else) on a stack to
> get a raster, which shows the regression slope of the pixels through the
> stack (treated like a kind of time series)?

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)


> And is it possible to compute a
> correlation between two stacks of the same dimensions?

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


> greetings,
> Martin
>
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/questions-on-RasterStack-Brick-tp5553580p5553580.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list