R/e_linear_interpolation.R
e_linear_interpolation.Rd
If all y are NA, then return y. If all non-NA y values are equal, then impute all y values equal. Otherwise, find at least two non-NA missing values to impute internal, starting, or ending NAs, in that order.
response values to impute via linear interpolation
spacing between y values
switch to indicate which missing values to replace: "all", "internal", "head" (starting), or "tail" (ending)
switch to indicate how to extrapolate to head and tail missing values. "martingale" sets NAs to closest non-NA value, while "linear" performs a linear extrapolation from the two closest non-NA values.
y Completed list of numbers
e_linear_interpolation(y = c(NA, NA, NA, NA, NA))
#> [1] NA NA NA NA NA
e_linear_interpolation(y = c(NA, NA, NA, 4, NA))
#> [1] 4 4 4 4 4
e_linear_interpolation(y = c(1, NA, 3, NA, 5))
#> [1] 1 2 3 4 5
e_linear_interpolation(y = c(1, NA, NA, NA, 5), x = c(1, 2, 4, 8, 16))
#> [1] 1.000000 1.266667 1.800000 2.866667 5.000000
e_linear_interpolation(y = c(NA, NA, NA, 4, 5), x = c(1, 2, 4, 8, 16), sw_extrapolation = "linear")
#> [1] 3.125 3.250 3.500 4.000 5.000
e_linear_interpolation(y = c(NA, NA, 3, 4, NA), x = c(1, 2, 4, 8, 16), sw_which = "head")
#> [1] 3 3 3 4 NA
e_linear_interpolation(y = c(NA, "a", NA, 3, 4, NA)) # warning for not numeric
#> Warning: e_linear_interpolation: Either y or x is not numeric, using martingale for non-numeric.
#> [1] "a" "a" "a" "3" "4" "4"