Message-ID: <CAE8g1gOWqG0jqhM5z0caaC=hMcvAsimwgpBi55PzsTRiGWM-NA@mail.gmail.com>
Date: 2016-05-16T18:32:04Z
From: Antonio Silva
Subject: getting mean values for each raster in a stack
Dear R users
I have a raster stack and a polygon.
I want the mean value inside this polygon for each raster in the stack.
I'm doing the following:
vals <- extract(stack,polygon)
colMeans(r.vals[[1]]) # only for mean values
# or
for (i in 1:nlayers(stack)) {print(mean(vals[[1]][,i]))} # mean or other
parameter
I also tried to use lapply, but I got only the overall mean with
lapply(vals, FUN=mean)
I wonder if there is a way to get the mean (and other parameters) for each
layer using lapply function.
Thanks in advance.
Antonio Olinto
[[alternative HTML version deleted]]