Skip to content

Instantly share code, notes, and snippets.

@xuanlongma
Created March 14, 2013 12:49
Show Gist options
  • Save xuanlongma/5161060 to your computer and use it in GitHub Desktop.
Save xuanlongma/5161060 to your computer and use it in GitHub Desktop.
aggregate daily rainfall time series to 16 day temporal resolution
## x: daily rainfall time series
## lindex: date stamps of the MOD13 VI product time series
## rindex = lindex + 15
## TODO: increase the efficiency by replace the loop use sapply
fun.aggre16d <- function(x, lindex, rindex) {
v.16d.rain <- vector('numeric', length(lindex))
for (i in 1:length(lindex)) {
v.16d.rain[i] <- sum(x[lindex[i]:rindex[i]], na.rm = T)
}
return(v.16d.rain)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment