| interpolate_missing | R Documentation |
Interpolate missing values in a numeric time series.
interpolate_missing(x, periods, ...)
x |
Numeric vector containing the time series observations. |
periods |
Numeric vector giving the seasonal periods of the time series,
for example |
... |
Further arguments passed to |
interpolate_missing() is a small wrapper around
forecast::na.interp(). The input vector is first converted to an
msts object using the seasonal periods supplied in periods.
For non-seasonal time series, missing values are replaced using linear
interpolation. For seasonal time series, forecast::na.interp() uses an
STL-based approach: the series is decomposed, the seasonally adjusted series
is interpolated, and the seasonal component is added back.
The function returns a plain numeric vector with the same length as the input.
A numeric vector with missing values interpolated.
Other data preparation:
check_data(),
smooth_outlier()
library(dplyr)
x <- M4_monthly_data |>
filter(series == first(series)) |>
pull(value)
x_missing <- x
x_missing[c(10, 20, 30)] <- NA
x_interpolated <- interpolate_missing(
x = x_missing,
periods = 12
)
anyNA(x_missing)
anyNA(x_interpolated)
hourly <- elec_price |>
filter(bidding_zone == "DE") |>
slice_head(n = 24 * 14) |>
pull(value)
hourly_missing <- hourly
hourly_missing[c(24, 48, 72)] <- NA
interpolate_missing(
x = hourly_missing,
periods = c(24, 168)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.