Description Usage Arguments Value Examples
Interpolate values
1 | interpolate(x, y, xout, method = "linear", extrapolate = TRUE)
|
x |
coordinate where data is avalaible. |
y |
vector of values measured at points |
xout |
vector giving the coordinates at which to interpolate. |
method |
interpolation method. When |
extrapolate |
when |
The vector of interpolated values at points xout
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | set.seed(1)
# interpolate numerical values
x <- jitter(1:10, 2)
y <- runif(10, 10, 100)
xout <- seq(0,11,by=0.1)
plot(x, y, type="b", xlim=c(0,11))
rug(x)
rug(xout, col="red")
points(xout, interpolate(x, y, xout, method="constant"), col="red")
points(xout, interpolate(x, y, xout, method="linear"), col="darkgreen", pch=4)
points(xout, interpolate(x, y, xout, method="spline", extrapolate=FALSE), col="blue", pch=3)
# interpolate a factor
x <- jitter(1:10, 2)
y <- factor(letters[1:2][round(runif(10, 1, 2))])
xout <- 1:10
plot(x, y, yaxt="n", ylim=c(0,3))
axis(2, at=1:2, labels=levels(y))
rug(x)
rug(xout, col="red")
points(xout, interpolate(x, y, xout, method="spline"), col="red")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.