R/MA.R

Defines functions MA

Documented in MA

MA <- function(y, order, pad = NULL) {
    order <- as.integer(order)
    if (order < 1L)
        stop("'order' must be a positive integer")
    n <- length(y)
    ma <- cumsum(y) / order
    ma[order:n] <- ma[order:n] - c(0, ma[1L:(n - order)])
    if (!is.null(pad) && order > 1L)
        ma[1L:(order - 1L)] <- pad
    ma
}

Try the NMOF package in your browser

Any scripts or data that you put into this service are public.

NMOF documentation built on Oct. 20, 2023, 9:07 a.m.