2

I would like to sumarize (sum and/or mean) values from layers on a raster brick based on latitude bands (been using raster package). Been looking at the package documentation and didn't find a way to do it. Can anyone give any advice on how to do it?

I guess one option would be to use extract by spatial polygons? Or is there a way to do it with another raster where the values would be classes of the latitudes of cells?

3

Your second option may be straightforward. You can use the 'init' and 'zonal' functions for that

library(raster)
r <- raster()
values(r) <-1:ncell(r)
zones <- init(r, v='y')
z <- zonal(r, zones, 'mean')
plot(z)

If the raster do not align (and you cannot fix that via aggregation) you could also use extract with polygons. E.g.:

a <- aggregate(zones, 10, mean)
p <- rasterToPolygons(a, dissolve=TRUE)
e <- extract(r, p, fun=mean)
plot(data.frame(p)[,1], e)
  • Thanks it was exactly the exactly the "zones <- init(r, v='y')" i was missing. Just as a side note found hovmoller's graph on rasterVis package that does exactly what I wanted to do (without knowing something like that existed). Anyway your answer was very useful. – Tnunes Jan 12 '14 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.