Description Usage Arguments Details Value Functions Examples
This function returns A matrix: the first column is the position, the second column the input vector, and third column simple moving average of the given vector. The weight argument is optional.
1 2 3 4 5 |
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) potions 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" |
This function is especially designed for Unevenly Spaced Time Series. It is efficient as it inherits the
similar routine of movMean
.
The result is kind of tricky. To make it clear, it is written to return a MATRIX. For instance, the
third column of the output of second example is NA, 2.5, 4.0, NA, NA, NA, 3.0, 3.0, 8.0.
2.5 is the average of 1 and 4, and 4.0 the average of 4. The third column of the output of
third example is the every third element starting from nth number.
For how weights, w, work, one can refer to movMean
.
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.
movMeanUEr
: An function equivalent to movMeanUE(..., align = "right")
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | movMeanUEr(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), 2)
movMeanUEr(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), n = 2, na_rm = TRUE)
movMeanUEr(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), n = 2, ss = 3, na_rm = TRUE,
sizeD = TRUE)
movMeanUE(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")
movMeanUE(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), n = 2, ss = 3,
na_rm = TRUE, sizeD = TRUE, align = "right")
movMeanUEr(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), n = 2, ss = 3,
na_rm = TRUE)
movMeanUEr(c(1, 4, 3, NA, 8), pos = c(1, 2, 7, 8, 9), n = 2, ss = 3, na_rm = TRUE,
sizeD = TRUE)
movMeanUE(rnorm(50), pos = sort(sample(1:100, 50, replace = FALSE)), n = 5,
ss = 10, na_rm = TRUE, align = "right")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.