approx[fun] {base} | R Documentation |
approx (x, y, xout, method="linear", n=50,
yleft, yright, rule=1, f=0)
approxfun(x, y, method="linear",
yleft, yright, rule=1, f=0)
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 |
specifies the interpolation method to be used. Choices
are |
n |
If |
yleft |
the value to be returned when input |
yright |
the value to be returned when input |
rule |
an integer describing how interpolation is to take place
outside the interval [ |
f |
For |
approx
returns a list with components x
and y
,
containing n
coordinates which interpolate the given data
points according to the method
(and rule
) desired.
The function approxfun
returns a function performing (linear or
constant) 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
.
spline
and splinefun
for spline
interpolation.
x <- 1:10
y <- rnorm(10)
par(mfrow = c(2,1))
plot(x, y, main = "approx(.) and approxfun(.)")
points(approx(x, y), col = 2, pch = "*")
points(approx(x, y, method = "constant"), col = 4, pch = "*")
f <- approxfun(x, y)
curve(f(x), 0, 10, col = "green")
points(x, y)
is.function(fc <- approxfun(x, y, method = "const")) # T
curve(fc(x), 0, 10, col = "darkblue", add = TRUE)