x <- c(1, 2, 3, 4, 5, 6)
y <- c(16, 18, 21, 17, 15, 12)
pchip(x, y, seq(1, 6, by = 0.5))
fp <- pchipfun(x, y)
fp(seq(1, 6, by = 0.5))
## Not run:
# plot(x, y, col="red", xlim=c(0,7), ylim=c(10,22),
# main = "Spline and 'pchip' Interpolation")
# grid()
#
# xs <- seq(1, 6, len=51)
# ys <- interp1(x, y, xs, "spline")
# lines(xs, ys, col="cyan")
# yp <- pchip(x, y, xs)
# lines(xs, yp, col = "magenta")## End(Not run)
Run the code above in your browser using DataLab