Taylor,

You can do something like this:

# example data as you described it
library(raster)
r <- raster(nc=10, nr=10)
s <- stack(sapply(1:600, function(x) setValues(r, runif(ncell(r)))) )
s

# create an index for each month
m <- rep(rep(1:12, each=2), 25)
m[1:30]
# variance for each cell for each month
x <- stackApply(s, m, var)
x

# perhaps better to first get the mean value for each
# month for each year
i <- rep(1:300, each=2)
s2 <- stackApply(s, i, mean)
nlayers(s2)

# and then compute the variance
j <- rep(1:12, each=25)
x2 <- stackApply(s2, j, var)
x2


This approach breaks down when your time intervals are more complex. In
that case it is good to use formal time objects and setZ, but here that
does not seem to be necessary.

Robert


On Thu, Oct 25, 2012 at 10:33 AM, Taylor Turner <taylorjt@me.com> wrote:

>
> > Hello R-masters,
> > I am relatively new to R and I am even newer to its use in GIS
> applications so please bear with me. I am currently using all available
> GIMMS of Africa (from '81 to '06) and I plan on plotting the mean NDVI
> variance of each month over the years (1981-2006) of several smaller ranges
> that I have cropped out and then stacked. Each stack consists of 600
> rasters - 24 semimonthly GIMMS for 25 years. Here is my problem: after
> reading various examples it seems that I first need to assign a z value
> (using setZ I presume). How can I categorize the 600 rasters into months
> and assign z values?
> >
> > Thanks,
> > T
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]

