Q:

Interpolating values in R (and avoiding negative interpolated values)

Is there any interpolation approach implemented in R where you can avoid interpolating missing values with negative value?
Let's take a vector:
d <- c(NA, NA, 5000, 17782, NA, NA, 21450, 42320, NA, NA, 52900, 54170, 
60600, 69000, 78000, 87000, 96900, 96900, 122000, 132700, 145000, 
171500, 198900, 213400, 229600, 250200, 272000, 291600, 318000, 
343000, 367000, 419200, 445000, 495000, 540000)

plot(d)

Using cubic spline interpolation 
library(zoo)  # for na.spline
d.interpolation <- na.spline(d)

this gives
[1] -100174.12  -31198.04    5000.00   17782.00   16961.75   14160.17   21450.00   42320.00   53674.83
[10]   54841.83   52900.00   54170.00   60600.00   69000.00   78000.00   87000.00   96900.00   96900.00
[19]  122000.00  132700.00  145000.00  171500.00  198900.00  213400.00  229600.00  250200.00  272000.00
[28]  291600.00  318000.00  343000.00  367000.00  419200.00  445000.00  495000.00  540000.00

However, negative values don't make to much sense in this context.
Obviously, something like
d.interpolation <- na.spline(c(0,d))

also won't work.
Do you have any solution to this?

A:

You could interpolate over log(d):
library(zoo)
d.interpolation <- exp(na.spline(log(d)))
d.interpolation
#  [1]      1.86    282.86   5000.00  17782.00  22424.08  19122.70  21450.00
#  [8]  42320.00  59826.52  58724.79  52900.00  54170.00  60600.00  69000.00
# [15]  78000.00  87000.00  96900.00  96900.00 122000.00 132700.00 145000.00
# [22] 171500.00 198900.00 213400.00 229600.00 250200.00 272000.00 291600.00
# [29] 318000.00 343000.00 367000.00 419200.00 445000.00 495000.00 540000.00

