[R-sig-Geo] Mean every 12 layers (months)

Jackson Rodrigues j@ck@onmrodrigue@ @ending from gm@il@com
Sun Nov 4 01:13:31 CET 2018


Hi fellows,

My name is Jackson.

I have 2 questions. I am gratful for any help for anyone.

----------------------
*Question 1*
Regarding extracting multiple mean from long raster file.
 I want to reduce 6000 layers (1 per month) to 500 (1 per year)

library(raster)
>TS20 = brick("trace.20.10200-09701BP.cam2.h0.TS.nc", level=1, var="TS")
#It extents from 10200 BP to 9701 BP- a total of 6000 layers (1 per month)
>TS20 = rotate(TS20)
>TS20
class       : RasterBrick
dimensions  : 48, 96, 4608, 6000  (nrow, ncol, ncell, nlayers)
resolution  : 3.75, 3.708898  (x, y)
extent      : -178.125, 181.875, -89.01354, 89.01354  (xmin, xmax, ymin,
ymax)

>indices<-rep(1:6000,each=12) #found somewhere 6000 layers / 12 months =
500 annual layers
>s.mean<-stackApply(TS20, indices, fun = mean)
Warning message:
In ind[] <- indices :
  number of items to replace is not a multiple of replacement length

#Why do I get this warning message?  My raster has 6000 layers, so my
indices should work, or not?
---------------------------
*Question 2*
how could rename my layers combining years and months ?
For example?
Layer 1 should be TS20$10200.Jan
Layer 2 should be TS20$10200.Feb
...
Layer 6000 should be TS20$9701.Dec

In the end I will calculate seasonal mean. So, this is why I would like to
rename them.

Thank you all,

Jackson

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list