This function below is doing good job for spline interpolation but I wonder how can I modify it to do linear interpolation instead!
## Function to interpolate using spline
imageSpline = function(x, y, xout, method = "natural", ...){
x.max = max(xout)
x.spline = spline(x = x, y = y, xout = xout, method = method, ...)
x.spline
}
See
?approx
forapprox()
andapproxFun()
. These are the linear interpolation counterparts tospline()
andsplineFun()
.Depending on the detail of the linear interpolation you want to perform (see
?approx
for the details and things to tweak), it could be as simple as: