[R] Interpolation

Ray Brownrigg ray at mcs.vuw.ac.nz
Wed Feb 12 12:13:05 CET 2003

> I have two vectors and connect the points by line segments:
> x <- c(1990,1994,1995,1997)
> y <- c(30,40,80,20)
> plot(x,y,type="l")
> I want to get the values of y's on these lines at missing x's,
> i.e., at 1991,1992,1993,and 1996. Is there a simple way to do this?
approx(x, y, c(1991:1993, 1996))$y
approx(x, y, 1990:1997)$y
will give you all the y values.

Hope this helps,
Ray Brownrigg <ray at mcs.vuw.ac.nz>	http://www.mcs.vuw.ac.nz/~ray

More information about the R-help mailing list