ROIpad ← Back to Search
stackoverflow › answer

Answer to: Interpolate data using indicator in time series

Score: 0
Answered: Nov 4, 2025
User Rep: 70,620
The na.spline function in the zoo package will take a zoo object and replace the NAs using a cubic spline interpolation. We could run df$Var_spline = zoo::na.spline(zoo::zoo(df$Variable, df$year)) and then see this works nicely with the data, interpolating between the known points and extrapolating beyond: ggplot(df, aes(year, Var_spline)) + geom_line(color = "gray70") + geom_point(shape = 21) + geom_point(aes(y = Variable))
r time-series
View Question ↗
Question
Parent Entity
Score: 2 • Views: 119
Site: stackoverflow