Apply approx Function to Multiple Coordinates
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.
Example:
In this example, we will be creating the vector accordingly having the multiple coordinates and then passing to the approx function to get the interpolates list of the vector passed further for the visualization we have to create the plot of the points.
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_approx1 <- approx (x, y) data_approx1 # Draw output of approx function plot (data_approx1$x, data_approx1$y) points (x, y, col = "red" , pch = 16) |
Output:
$x
[1] 1.000000 1.163265 1.326531 1.489796 1.653061 1.816327 1.979592 2.142857 2.306122 2.469388 2.632653 2.795918 2.959184
[14] 3.122449 3.285714 3.448980 3.612245 3.775510 3.938776 4.102041 4.265306 4.428571 4.591837 4.755102 4.918367 5.081633
[27] 5.244898 5.408163 5.571429 5.734694 5.897959 6.061224 6.224490 6.387755 6.551020 6.714286 6.877551 7.040816 7.204082
[40] 7.367347 7.530612 7.693878 7.857143 8.020408 8.183673 8.346939 8.510204 8.673469 8.836735 9.000000
$y
[1] 0.00000000 0.05442177 0.10884354 0.16326531 0.21768707 0.27210884 0.32653061 0.38095238 0.43537415 0.48979592
[11] 0.54421769 0.59863946 0.65306122 0.70748299 0.76190476 0.81632653 0.87074830 0.92517007 0.97959184 1.81632653
[21] 3.12244898 4.42857143 5.73469388 7.04081633 8.34693878 8.83673469 8.51020408 8.18367347 7.85714286 7.53061224
[31] 7.20408163 6.81632653 6.32653061 5.83673469 5.34693878 4.85714286 4.36734694 4.08163265 4.40816327 4.73469388
[41] 5.06122449 5.38775510 5.71428571 5.97959184 5.81632653 5.65306122 5.48979592 5.32653061 5.16326531 5.00000000
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.