Skip to content
Prev 24037 / 29559 Next

Count frequency in raster stacks

Nice, Robert! Thanks for showing up and contributing to this question!?Greetings,?-- Thiago V. dos Santos
PhD studentLand and Atmospheric ScienceUniversity of Minnesota
On Wednesday, February 17, 2016 11:02 PM, Robert J. Hijmans <r.hijmans at gmail.com> wrote:
Here is a more direct (and safer) way:

library(raster)
set.seed(0)
r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
s <- stack(lapply(1:5, function(x) {setValues(r, round(runif(22 * 20,
min=0, max=600), digits=0))}))


intervals <- seq(0, 600, 100)

x <- cut(s, intervals, include.lowest=TRUE)
freq(x, merge=TRUE)



On Wed, Feb 17, 2016 at 4:54 PM, Thiago V. dos Santos
<thi_veloso at yahoo.com.br> wrote: