I'm trying to perform linear extrapolation and can't figure out the correct notation to apply the approxExtrap function from the Hmisc package. I have seen some examples, but none that I've been able to apply. I have been able to use the normal approx function specifying only the "x" argument, being the variable I want to interpolate. Doing the following leaves me with an error. Any suggestions? Thank you!
library(tidyverse)
library(zoo)
library(Hmisc)
#write data frame
df <- tibble(day=1:10,
sales = c(NA, NA, NA, 4, 5, 6, 7, 8 , 9, 10))
#attempt to perform extrapolation
df <- df %>%
mutate(sales=approxExtrap(x=sales, y=NULL))
Error in `mutate()`:
! Problem while computing `sales = approxExtrap(x = sales, y = NULL)`.
Caused by error in `approx()`:
! need at least two non-NA values to interpolate