Answer to: Interpolate data using indicator in time series
Score: 0
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))
View Question ↗
Question
Parent Entity
Score: 2 • Views: 119
Site: stackoverflow
Other Comments / Reviews
SaaS Metrics