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.

Similar Reads

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....

Method 1: Apply approx Function to Two Coordinates

In this method, we will be applying the approx function to two coordinates using the approx function passed with the given vector as its parameters to get a list of points which interpolate given two different data points....

Method 2: Apply approx Function to Multiple Coordinates

...

Method 3: Create a User-Defined Interpolation Function Using approxfun

In this method to apply an approx function to multiple coordinates, the user has to create the vectors containing multiple coordinates which further have to be passed as done in the above approach function which will be returning the linearly interpolates a list of the vector passed to the user....