period.apply | R Documentation |
Apply specified function over each period of date/time defined in INDEX at each grid cell.
period.apply(x, INDEX, FUN, ...)
x |
a raster time series ( |
INDEX |
a numeric vector of endpoints of time/date periods to apply function over |
FUN |
an argument of type |
... |
additional arguments for |
This functions subsets the raster data based on the specified time periods (endpoint for each period should be specified in INDEX
), and FUN
function will be applied to the subsetted values at each grid cell for each period. For each period, a raster will be calculated and the end of the date/time period will be assigned to it in the output raster time series object. If the INDEX
is out of range, the function stops working and an error is generated.
RasterStackTS or RasterBrickTS
Babak Naimi
period.apply
## Not run:
file <- system.file("external/ndvi", package="rts")
ndvi <- rts(file) # read the ndvi time series from the specified file
ndvi
ep <- endpoints(ndvi,'years') # extract the end index on each year period
ndvi.y <- period.apply(ndvi,ep,mean) # apply the mean function on each year
ndvi.y
#---------
ep <- endpoints(ndvi,'quarters') # extract the end index on each quarter of a year
# a function:
f <- function(x) {
if (min(x) > 0.5) mean(x)
else 0
}
ndvi.q <- period.apply(ndvi,ep,f) # apply the function f on each quarter
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.