period.apply: Apply a function over specified time intervals

period.applyR Documentation

Apply a function over specified time intervals

Description

Apply specified function over each period of date/time defined in INDEX at each grid cell.

Usage

period.apply(x, INDEX, FUN, ...) 

Arguments

x

a raster time series (Raster*TS) object created by rts

INDEX

a numeric vector of endpoints of time/date periods to apply function over

FUN

an argument of type function

...

additional arguments for FUN

Details

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.

Value

RasterStackTS or RasterBrickTS

Author(s)

Babak Naimi

naimi.b@gmail.com

https://r-gis.net/

See Also

period.apply

Examples

## 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)


rts documentation built on Oct. 1, 2023, 9:07 a.m.

Related to period.apply in rts...