Log-linear interpolation of NA values

log_linear_interp(y, x, rule = 2, replace_na = 0)

Arguments

y

vector of output values, possibly with NAs

x

vector of points to interpolate (no NAs)

rule

rule for extrapolating outside range (see approx())

replace_na

value to replace if interpolation evaluates to NA

Examples

log_linear_interp(c(100, 105, NA, 110), 1:4)
#> [1] 100.0000 105.0000 107.4709 110.0000
log_linear_interp(c(NA, 105, NA, 110), 1:4)
#> [1] 105.0000 105.0000 107.4709 110.0000
log_linear_interp(c(NA, 105, NA, 110, NA), 1:5, rule = 1)
#> [1]   0.0000 105.0000 107.4709 110.0000   0.0000
log_linear_interp(c(NA, 105, NA, 110, NA), 1:5, rule = 2)
#> [1] 105.0000 105.0000 107.4709 110.0000 110.0000
log_linear_interp(c(NA, NA, 37), 1:3, rule = 2)
#> [1] 37 37 37