I have to fill missing data in a tsibble
with imputeTS
.
I want to limit the number of consecutive NAs to be filled with maxgap
.
Any maxgap
value different from Inf
gives an error.
library(tsibble)
library(imputeTS)
harvest <- tsibble(
year = c(2010, 2011, 2011, 2014),
fruit = rep(c("kiwi", "cherry"), each = 2),
kilo = sample(1:10, size = 4),
key = fruit,
index = year
)
# Not Working
harvest |>
fill_gaps(.full = TRUE) |>
na_kalman(maxgap = 1)
# Working
harvest |>
fill_gaps(.full = TRUE) |>
na_kalman(maxgap = Inf)
na_kalman: No imputation performed for column 3 of the input dataset. Reason: 'x' must be a vector of an atomic type
How can I solve the error?