Linear Interpolation of Points

DESCRIPTION:
Returns a list of x values and corresponding y values which are linear interpolations from the input.

USAGE:
approx(x, y, xout=<<see below>>, method="linear", n=50, rule=1, f=0)

REQUIRED ARGUMENTS:
x,y:
coordinates of points. The coordinates can be given by two arguments that are vectors or by a single argument x which is a univariate time series, a complex vector, a matrix with 2 columns, or a list containing components named x and y. The y values represent the curve to be approximated as a function of x. Missing values are not accepted.

OPTIONAL ARGUMENTS:
xout:
set of x values for which function values are desired. If xout is not specified, the function will be approximated at n equally spaced data points, spanning the range of x.
method:
character describing the method to be used in approximating the function. This must be either "linear" or "constant".
n:
integer giving the number of points evenly spaced between the minimum and maximum values in x to be used in forming xout. This argument is ignored if xout is specified.
rule:
integer describing the rule to be used for values of xout that are outside the range of x. If rule is 1, NAs will be supplied for any such points. If rule is 2, the y values corresponding to the extreme x values will be used.
f:
a number used when method="constant", f determines a blend of the left and right side y values. Suppose we want an interpolated value between x1 and x2 (with corresponding y values y1 and y2). Then the interpolated value is f*y1+(1-f)*y2. Thus, if f=0, the left y-value is used, if f=1, the right y-value, and if f is between 0 and 1, an intermediate value is used.

VALUE:
list with components named x and y. The x component corresponds to xout, the y component is the linear interpolation of the input data. No smoothing is performed.

SEE ALSO:
interp , spline , lowess , supsmu .

EXAMPLES:
z <- approx(x,y,newx)   # linear interpolation at newx
quants <- approx(ppoints(x),sort(x),c(.1,.25,.5,.75,.9))$y
   # get the 10, 25, 50, 75 and 90 percentiles of x
   # see also function quantile