[ top | up ]

Linear Interpolation

Syntax

approx(x, y, xout, method="linear", n=50, rule=1)

Arguments

x,y vectors giving the coordinates of the points to be interpolated. Alternatively a single plotting structure can be specified.
xout an optional set of values specifying where interpolation is to take place.
method this specifies the interpolation method to be used. Currently this is ignored and linear interpolation is always used.
n If xout is not specified, interpolation takes place at n equally spaced points spanning the interval [min(x),max(x)].
rule an integer describing how interpolation is to take place outside the interval [min(x),max(x)]. If rule is 1 then NAs are returned for such points and if it is 2, the value at the closest data extreme is used.

Value

A list containing n x and y coordinates which linearly interpolate the given data points.

The function approxfun returns a function which will perform linear interpolation of the given data points. For a given set of x values this function will return the corresponding interpolated values. This is often more useful than approx.

See Also

approxfun, spline, splinefun.

Examples

x <- 1:10 y <- rnorm(10) plot(x, y) points(approx(x, y))