Open In App
Related Articles

Get a List of points obtained by Interpolation in R Programming – spline() and splinefun() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

In R programming, spline() and splinefun() function is used to create a list of points obtained by interpolation. It performs cubic spline interpolation of given data points.

Syntax:
spline(x, y, method)
and
splinefun(x, y, method)

Parameters:
x, y: represents vectors giving the points for interpolation
method: represents the type of spline interpolation to be used

To know about more optional parameters of both the functions, use below command in console:

help("spline")

Example 1:




# Coordinates
n <- 100
x <- 1:n
y <- rnorm(n)
  
# Output to be present as PNG file
png(file = "splineGFG.png")
  
# Spline() function
plot(x, y, main = "spline() function")
lines(spline(x, y))
  
# Saving the file
dev.off()


Output:

Example 2:




# Coordinates
n <- 100
x <- 1:n
y <- sin((x-0.5)*pi)
  
# Output to be present as PNG file
png(file = "splinefunGFG.png")
  
f <- splinefun(x, y)
curve(f(x))
  
# Saving the file
dev.off()


Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 03 Jul, 2020
Like Article
Save Article
Previous
Next
Similar Reads