Joanna:

I think the function you are looking for is ?cellStats -- I don't see any
documentation that allows you to use mean with a range of indexes (and have
it figure out you mean the z-axis).  When in doubt, I usually use stack()
to make a virtual subset of the input brick to control what goes into the
function.  Good luck!

--j


On Fri, Feb 8, 2013 at 10:35 AM, Whittier, Joanna B. <whittierj@missouri.edu
> wrote:

> When calculating mean from a subset of layers within a raster brick, I get
> a single layer with one value for all cells.  If I do not try to take the
> mean of a subset of data, then I get the correct values.  The output
> dimensions are correct in both cases.  The original data is a netcdf file
> for the years 2001 -2100.  I need the mean for years 2046 - 2100. From
> looking at the examples in the raster package documentation, I think I
> coded correctly to calculate the mean across years, but apparently I am
> wrong.  Can anyone tell me how to code this correctly?
>
> Thank you,
> JW
>
> This is the coding and output when I try to calculate the mean for 2046 -
> 2100.
> > mean_ttl_precip_flux=NULL
> > mean_ttl_precip_flux<-mean(ncr1,541:1200)
> > mean_ttl_precip_flux
> class       : RasterLayer
> dimensions  : 48, 96, 4608  (nrow, ncol, ncell)
> resolution  : 3.75, 3.708898  (x, y)
> extent      : -1.875, 358.125, -89.01354, 89.01354  (xmin, xmax, ymin,
> ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : in memory
> names       : layer
> values      : 308.8871, 308.8872  (min, max)
>
> This is the coding and output if I do not try to specify particular years.
> > mean_ttl_precip_flux=NULL
> > mean_ttl_precip_flux<-mean(ncr1)
> > mean_ttl_precip_flux
> class       : RasterLayer
> dimensions  : 48, 96, 4608  (nrow, ncol, ncell)
> resolution  : 3.75, 3.708898  (x, y)
> extent      : -1.875, 358.125, -89.01354, 89.01354  (xmin, xmax, ymin,
> ymax)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> data source : in memory
> names       : layer
> values      : 6.547268e-07, 0.0001545883  (min, max)
>
> -----Original Message-----
> From: Roger Bivand [mailto:Roger.Bivand@nhh.no]
> Sent: Friday, February 08, 2013 10:00 AM
> To: Whittier, Joanna B.
> Cc: r-sig-geo-owner@r-project.org
> Subject: Re: FW: error in calculating mean of a raster brick
>
> Jodi,
>
> You are not subscribed to this list with your name or
> whittierj@missouri.edu. Since you tried posting through nabble, had you
> checked that you are fully subscribed to the list, or only to nabble?
> Subscribe directly at:
>
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> and wait to see traffic arriving first before trying to post.
>
> Roger Bivand
> List admin.
>
> On Fri, 8 Feb 2013, Whittier, Joanna B. wrote:
>
> > Hi - sorry to bother you but yesterday I registered and posted a
> > question but then received the below message.  Did I need to wait for
> > some period of time before posting a question?
> >
> > Thank you,
> > Jodi
> >
> > -----Original Message-----
> > From: r-sig-geo-bounces@r-project.org
> > [mailto:r-sig-geo-bounces@r-project.org] On Behalf Of
> > r-sig-geo-owner@r-project.org
> > Sent: Thursday, February 07, 2013 4:03 PM
> > To: Whittier, Joanna B.
> > Subject: error in calculating mean of a raster brick
> >
> > You are not allowed to post to this mailing list, and your message has
> been automatically rejected.  If you think that your messages are being
> rejected in error, contact the mailing list owner at
> r-sig-geo-owner@r-project.org.
> >
> >
>
> --
> Roger Bivand
> Department of Economics, NHH Norwegian School of Economics, Helleveien 30,
> N-5045 Bergen, Norway.
> voice: +47 55 95 93 55; fax +47 55 95 95 43
> e-mail: Roger.Bivand@nhh.no
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
Jonathan A. Greenberg, PhD
Assistant Professor
Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
Department of Geography and Geographic Information Science
University of Illinois at Urbana-Champaign
607 South Mathews Avenue, MC 150
Urbana, IL 61801
Phone: 217-300-1924
http://www.geog.illinois.edu/~jgrn/
AIM: jgrn307, MSN: jgrn307@hotmail.com, Gchat: jgrn307, Skype: jgrn3007

	[[alternative HTML version deleted]]

