Message-ID: <CAE8g1gMogzdNcPgWr_dUdxM5ejOdNhwnwf139v2maYtzHV8zLw@mail.gmail.com>
Date: 2016-05-16T21:14:56Z
From: Antonio Silva
Subject: getting mean values for each raster in a stack
In-Reply-To: <573A352F.3050207@uni-muenster.de>
Dear Pebesma
No I din't, thanks. Probably I have not read enough.
extract package:raster
fun: function to summarize the values (e.g. ?mean?). The function
should take a single numeric vector as argument and return a
single value (e.g. mean, min or max), and accept a ?na.rm?
argument ... ??
Thanks again.
A.O.
2016-05-16 18:01 GMT-03:00 Edzer Pebesma <edzer.pebesma at uni-muenster.de>:
> Did you try:
>
> extract(stack, polygon, mean)
>
> ?
>
> On 16/05/16 22:50, Antonio Silva wrote:
> > Hi,
> >
> > After many trials and some reading I got what I need
> >
> > apply(vals[[1]],2,mean)
> >
> > Anyway I would welcome comments to improve this solution.
> >
> > Best regards
> >
> > Antonio Olinto
> >
> >
> > 2016-05-16 15:32 GMT-03:00 Antonio Silva <aolinto.lst at gmail.com>:
> >
> >> 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
> >>
> >>
> >
> >
>
> --
> Edzer Pebesma
> Institute for Geoinformatics (ifgi), University of M?nster
> Heisenbergstra?e 2, 48149 M?nster, Germany; +49 251 83 33081
> Journal of Statistical Software: http://www.jstatsoft.org/
> Computers & Geosciences: http://elsevier.com/locate/cageo/
> Spatial Statistics Society http://www.spatialstatistics.info
>
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Ant?nio Olinto ?vila da Silva
Bi?logo / Ocean?grafo
Instituto de Pesca (Fisheries Institute)
S?o Paulo, Brasil
[[alternative HTML version deleted]]