Convert spline interpolation to linear interpolati

2019-09-02 11:27发布

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
    }

标签: r
1条回答
走好不送
2楼-- · 2019-09-02 11:57

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
}
查看更多
登录 后发表回答