# a time vector
tt <- 2011:2020
# two random vectors with some missing values
y1 <- runif(10)
y2 <- runif(10)
y1[2] <- y1[5] <- NA
y2[3] <- y2[5] <- NA
# make into df
Y <- data.frame(y1, y2)
# interpolate for time = 2012
Y_int <- approx_df(Y, tt, 2012)
Y_int$Y
# notice Y_int$y2 is unchanged since at 2012 it did not have NA value
stopifnot(identical(Y_int$Y$y2, y2))
# interpolate at value not in tt
approx_df(Y, tt, 2015.5)
Run the code above in your browser using DataLab