I want to adjust the end values of interpolation for missing values in such a way that the difference between the next set of non-NA values are applied to determine the first one. for example, this is the code
library(zoo)
> na.approx(c(NA,10,8,NA,7,NA,NA,NA,11),na.rm = FALSE)
[1] NA 10.0 8.0 7.5 7.0 8.0 9.0 10.0 11.0
> na.approx(c(NA,10,8,NA,7,NA,NA,NA,11), na.rm = FALSE, rule=2)
[1] 10.0 10.0 8.0 7.5 7.0 8.0 9.0 10.0 11.0
Instead of the initial 10, i want it to be 12 (difference between the 2nd and the 3rd elements carried to the previous interpolation). There is the combination of Shift's I could use, after applying the na.approx without na.rm option. But is there an Na.approx or an approx functionality that I could use?