R: Apply a function over a time series.

sits_apply {sits} | R Documentation

## Apply a function over a time series.

### Description

Apply a 1D generic function to a time series and specific methods for common tasks, such as missing values removal and smoothing. 'sits_apply()' returns a sits tibble with the same samples and new bands computed by 'fun', 'fun_index' functions. These functions must be defined inline; they are called by 'sits_apply' for each band, whose vector values is passed as the function argument. The 'fun' function may either return a vector or a list of vectors. In the first case, the vector will be the new values of the corresponding band. In the second case, the returned list must have names, and each element vector will generate a new band which name composed by concatenating original band name and the corresponding list element name.

If a suffix is provided in 'bands_suffix', all resulting band names will end with provided suffix separated by a ".".

### Usage

    sits_apply(
      data,
      fun,
      fun_index = function(index) {     return(index) },
      bands_suffix = "",
      multicores = 1
    )

### Arguments

`data` | Valid sits tibble
`fun` | Function with one parameter as input and a vector or list of vectors as output.
`fun_index` | Function with one parameter as input and a Date vector as output.
`bands_suffix` | String informing the suffix of the resulting bands.
`multicores` | Number of cores to be used

### Value

A sits tibble with same samples and the new bands.

### Author(s)

Rolf Simoes, rolf.simoes@inpe.br

### Examples

    # Get a time series
    point_ndvi <- sits_select(point_mt_6bands, bands = "NDVI")
    # apply a normalization function
    point2 <- sits_apply(point_ndvi,
        fun = function(x) {
            (x - min(x)) / (max(x) - min(x))
        }
    )

[Package sits version 0.14.1 Index]