movSumUE: Weighted Simple Moving Sum for Unevenly Spaced Time Series In RcppMovStat: Fast Moving Statistics Calculation

Description

This function returns A matrix: the first column is the position, the second column the input vector, and third column moving sum of the given vector. The weight argument is optional.

Usage

 1 2 3 4 5 movSumUE(vec, pos, n = 1L, ss = 1L, w = NULL, na_rm = FALSE, sizeD = FALSE, align = "left") movSumUEr(vec, pos, n = 1L, ss = 1L, w = NULL, na_rm = FALSE, sizeD = FALSE)

Arguments

 vec A numeric vector. pos A numeric vector with all integers. Its length must be the SAME as vec. N.B. We use integers to represent the (relative) positions of every point. n An integer: moving window size, with 1 as default ss An integer: step size, only calculating at points with an equal distance ss. Namely, there are ss-1 number between each two 'consecutive' points w An optional weight vector of length n. It will be automatically normalized (sum to 1). na_rm logical. Should missing values (including NaN) be removed? sizeD logical. Only applied when ss > 1, it decides whether to get a result of smaller size. If sizeD = T, align does not affect the output. align A string denotes how to align the moving average, three options: "left", "middle", "right"

Details

This function can obtain the moving sum efficiently. It serves as somehow a generalized version of movMeanUE. The difference is that it will not automatically normalized the weights vector, w argument.
If there is no missing value in vec, and w is normalized, which means the sum of all elements is 1, this function will return a moving average. For matrix details, please refer to details of movMeanUE.

Value

This function returns A MATRIX of size: L*3, where L is the length of vector, or of size: L1*3, where L1 = ceiling((nrow - n + 1)/ss), (when sizeD = T). In the matrix, the first column denotes the position, the second column the original vector, and the third column the moving average.

Functions

• movSumUEr: An function equivalent to movSumUE(..., align = "right")

Examples

 1 2 3 4 5 6 7 8 9 10 11 12 movSumUEr(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), 2) movSumUEr(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), n = 2, na_rm = TRUE) movSumUEr(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), n = 2, ss = 3, na_rm = TRUE, sizeD = TRUE) movSumUE(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), w = c(0, 1), n = 2, ss = 3, na_rm = TRUE, align = "right") movSumUE(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), n = 2, ss = 3, na_rm = TRUE, sizeD = TRUE, align = "right") movSumUEr(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), n = 2, ss = 3, na_rm = TRUE) movSumUEr(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), n = 2, ss = 3, na_rm = TRUE, sizeD = TRUE)

RcppMovStat documentation built on Jan. 30, 2018, 5:04 p.m.