[R] Linear interpolation to calculate x when y=0

Daniel Halligan daniel.halligan at ed.ac.uk
Fri Oct 27 17:56:50 CEST 2006


I have approximated a function y = f(x) by sampling at different  
values of x.  The curve produced by joining up the points crosses y=0  
zero at two points, which are within the range of x values sampled  
and I would like to estimate (approximately) the x values at these  
points.  I think this is best done using linear interpolation, but I  
am stuck as how to do this.

Here is a data.frame containing the y and x values.
data.frame(x = c(0.00000, 0.00010, 0.00100, 0.01000, 0.02404,  
0.07603, 0.10000, 0.12021, 0.15146, 0.19083, 0.24007, 0.24043,  
0.24049, 0.30292, 0.38166, 0.48086, 0.76031, 1.00000, 2.00000,  
2.40430), y=c(-10.173, -5.046, -2.691, -0.093, 0.791, 1.643, 1.782,  
1.858, 1.933, 1.982, 2.000, 2.000, 2.000, 1.980, 1.913, 1.786, 1.318,  
0.866, -0.846, -1.397))

Any help greatly appreciated.

Dan Halligan

(P.S. I posted a similar question earlier, I hope this is simpler and  
better phrased)



More information about the R-help mailing list