Description Usage Arguments Details Value Author(s) Examples
Compute summary statistics on a sliding window along a vector containing data where the positions of the data points are stored in another vector.
1 2 | sliding_window(x, pos, start, width, advance, stat = c("mean", "median",
"min", "max", "sd"))
|
x |
A numeric vector containing the values. |
pos |
A incresingly sorted vector containing the corresponding positions. |
start |
A double. The starting point of the sliding window. |
width |
A double. The width of the sliding window. |
advance |
A double. The step size of the sliding window. |
stat |
A string. The summary statistic to be calculated. |
Note that only windows that fully fit into the range of pos
are
considered.
A data.frame
with columns start
(start of the
window), end
(end of the window), stat
(the computed
summary statistic) and n
(number of data points in the window).
Dominik Mueller (dominikmueller64@yahoo.de).
1 2 3 4 5 6 7 8 9 10 11 12 | set.seed(123L)
n <- 1000L
x <- arima.sim(n = n, list(ar = 0.99))
pos <- sort(runif(n))
plot(x = pos, y = x)
advance <- 0.01
width <- c(0.02, 0.1, 0.2)
colors <- c('red', 'green', 'blue')
for (i in seq_along(width)) {
df <- sliding_window(x, pos, 0.0, width[i], advance, "mean")
points(x = df$begin + width[i] / 2, df$stat, col = colors[i], pch = 19, lwd = 2.0, type = 'l')
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.