Skip to content
Prev 23747 / 29559 Next

How to calculate decadal average and percent change in raster stacks?

Oh, I should have said "10-year period", and not "9-year period".

This is because the first year of the decade should be accounted for, i.e. 2010 (including) to 2019.
 Greetings,
 -- Thiago V. dos Santos

PhD student
Land and Atmospheric Science
University of Minnesota
On Tuesday, December 1, 2015 2:04 PM, Thiago V. dos Santos <thi_veloso at yahoo.com.br> wrote:
Thanks you all for the responses. Each of them provided very good tips on how to address my problem.

Lo?c, answering your question: the percent change would be within the 9-year period of each decade. Thanks for your response, it was really concise.
Greetings,
-- Thiago V. dos Santos

PhD student
Land and Atmospheric Science
University of Minnesota
On Tuesday, December 1, 2015 4:40 AM, Lo?c Dutrieux <loic.dutrieux at wur.nl> wrote:
Hi Thiago,

This should work for aggregating to decades.

library(raster)
library(lubridate)

# Create the date sequence
idx <- seq(as.Date("2010/1/1"), as.Date("2099/12/31"), by = "year")

# Create raster stack and apply the date
r <- raster(ncol=360, nrow=180)
s <- stack(lapply(1:length(idx), function(x) setValues(r, runif(ncell(r)))))
s <- setZ(s, idx)

# Aggregate to decades
zApply(s, by = function(x) year(x) %/% 10 * 10, fun = mean)


By calculate percent change for each decade, do you mean between decades 
or within?

Cheers,
Lo?c
On 12/01/2015 09:14 AM, Thiago V. dos Santos wrote:

            
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo