Approx() and Approxfun() interpolation function
These functions return a list of points that linearly interpolates given data points, or a function performing the linear (or constant) interpolation.
Syntax:
- approx (x, y = NULL, xout, method = “linear”, n = 50,
yleft, yright, rule = 1, f = 0, ties = mean)- approxfun(x, y = NULL, method = “linear”,
yleft, yright, rule = 1, f = 0, ties = mean)Parameters:
- x, y :numeric vectors giving the coordinates of the points to be interpolated.
- xout: an optional set of numeric values specifying where interpolation is to take place.
- method:specifies the interpolation method to be used. Choices are “linear” or “constant”.
- n:If xout is not specified, interpolation takes place at n equally spaced points spanning the interval [min(x), max(x)].
- yleft: the value to be returned when input x values are less than min(x).
- yright: the value to be returned when input x values are greater than max(x).
- rule:an integer (of length 1 or 2) describing how interpolation is to take place outside the interval [min(x), max(x)].
- ties: handling of tied x values.
Interpolation Functions in R
In this article, we will be looking towards the approx() and the aproxfun() interpolation function with working examples in the R Programming language.