There is the imputeTS package, which specifically focuses on missing values in time series. (take a look at this Paper)
It works like this:
na_kalman(yourTimeSeries)
That's it already.
It offers several time series imputation functions:
- Imputation by Linear Interpolation
- Imputation by Spline Interpolation
- Imputation by Stineman Interpolation
- Imputation by Structural Model & Kalman Smoothing
- Imputation by ARIMA State Space Representation & Kalman Sm.
- Imputation by Last Observation Carried Forward
- Imputation by Next Observation Carried Backward
- Missing Value Imputation by Simple Moving Average
- Imputation by Linear Weighted Moving Average
- Imputation by Exponential Weighted Moving Average
- Missing Value Imputation by Mean Value
- Seasonally Decomposed Missing Value Imputation
- Seasonally Splitted Missing Value Imputation
Some of these functions are more advanced some are less advanced. I would try the na_kalman() function of the package for this task.
Might be that the results of this function already adhere the constraints.
Otherwise you need to perform some transformations before performing the imputation (as explained below).
In general if you want your imputation to be constrained to some bounds this transformation approach might also help:
library("imputeTS")
# Bounds
a <- 50
b <- 400
# Transform data
y <- log((myTimeSeries-a)/(b-myTimeSeries))
imputations <- na_kalman(y)
# Back-transform
imputationsBack <- (b-a)*exp(imputations)/(1+exp(imputations)) + a