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:
n <- 100
x <- 1:n
y <- rnorm (n)
png (file = "splineGFG.png" )
plot (x, y, main = "spline() function" )
lines ( spline (x, y))
dev.off ()
|
Output:

Example 2:
n <- 100
x <- 1:n
y <- sin ((x-0.5)* pi )
png (file = "splinefunGFG.png" )
f <- splinefun (x, y)
curve ( f (x))
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