Create a User-Defined Interpolation Function Using approxfun
In this method to create a user-defined interpolation function, the user needs to call the approxfun() function and passed the required parameters to get the interpolation accordingly in the R programming language.
Example:
In this example, we will be creating the vector accordingly and passing this given vector to the approxfun function, and plotting the plot of the x and y points with the curve given by the approxfun function in the R programming language.
R
# Create vector x <- c (1,8,9,4,7,6,5) y <- c (0,6,5,1,4,7,9) # Apply approx function data_approxfum <- approxfun (x, y) data_approxfum # Draw output of approx function plot (x, y) curve (data_approxfum, add = TRUE ) |
Output:
function (v) .approxfun(x, y, v, method, yleft, yright, f, na.rm) <bytecode: 0x000001bf4ba22068> <environment: 0x000001bf4d2c0408>
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.