adjust_linear.Rd
Adjust a regular time series for an assumed linear drift over a known period while maintaining an assumed linear trend over the entire period.
adjust_linear(x, mask)
x | A vector of data with missing values. |
---|---|
mask | A logical mask that identifies a subgroup of |
The vector x
with corrected values for the subgroup
specified by mask
.
# no trend, only drift x = rnorm(100, 10) + 0.1 * (1:100) newx = adjust_linear(x) if (interactive()) { plot(x, type = 'l') lines(newx, col = 'red') } # trend and drift x = rnorm(100, 10) - 0.05 * (1:100) mask = seq_along(x) %in% 20:80 x[mask] = x[mask] - 0.1 * cumsum(mask)[mask] newx = adjust_linear(x, mask) if (interactive()) { plot(x, type = 'l') lines(newx, col = 'red') }