[R-sig-Geo] error in calculating mean of a raster brick

Whittier, Joanna B. whittierj at missouri.edu
Fri Feb 8 17:35:32 CET 2013


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 at nhh.no] 
Sent: Friday, February 08, 2013 10:00 AM
To: Whittier, Joanna B.
Cc: r-sig-geo-owner at 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 at 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 at r-project.org 
> [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of 
> r-sig-geo-owner at 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 at 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 at nhh.no



More information about the R-sig-Geo mailing list