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
for approx()
and approxFun()
. These are the linear interpolation counterparts to spline()
and splineFun()
.
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:
imageApprox <- function(x, y, xout, ...) {
x.linear <- approx(x = x, y = y, xout = xout, ...)
x.linear
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.