Helper function to compute 'moving' functions, such as the 'moving average'
Usage
movingFun(x, n, fun=function(x){mean(x, na.rm=TRUE)}, type='around', circular=FALSE)
Arguments
x
A vector
n
Size of the 'window', i.e. the number of sequential elements to use in the function
fun
A function like mean, min, max, sum
type
Character. One of 'around', 'to', or 'from'. The choice indicates which values should be used in the computation. The focal element is always used. If type is 'around', the other elements are before and after the focal element. Alternatively,
circular
Logical. If true, the data are considered to have a circular nature (e.g. months of the year), and the last elements in vector x are used in the computation of the moving function of the first element(s) of the vector, and the fi