[R] interpolation to abscissa

e-letter inpost at gmail.com
Tue Jan 13 15:22:41 CET 2009


On 08/01/2009, Greg Snow <Greg.Snow at imail.org> wrote:
> If you want to just linearly interpolate, then use the functions approx or
> approxfun from the stats package (one of those that is loaded by default).
I have read the guide for approx and approxfun functions. Below is my data.

x=c(0,5,10,15,20)
y=c(16,45,77,101,125)

approx(x,y,method="linear")
$x
 [1]  0.0000000  0.4081633  0.8163265  1.2244898  1.6326531  2.0408163
 [7]  2.4489796  2.8571429  3.2653061  3.6734694  4.0816327  4.4897959
[13]  4.8979592  5.3061224  5.7142857  6.1224490  6.5306122  6.9387755
[19]  7.3469388  7.7551020  8.1632653  8.5714286  8.9795918  9.3877551
[25]  9.7959184 10.2040816 10.6122449 11.0204082 11.4285714 11.8367347
[31] 12.2448980 12.6530612 13.0612245 13.4693878 13.8775510 14.2857143
[37] 14.6938776 15.1020408 15.5102041 15.9183673 16.3265306 16.7346939
[43] 17.1428571 17.5510204 17.9591837 18.3673469 18.7755102 19.1836735
[49] 19.5918367 20.0000000

$y
 [1]  16.00000  18.36735  20.73469  23.10204  25.46939  27.83673  30.20408
 [8]  32.57143  34.93878  37.30612  39.67347  42.04082  44.40816  46.95918
[15]  49.57143  52.18367  54.79592  57.40816  60.02041  62.63265  65.24490
[22]  67.85714  70.46939  73.08163  75.69388  77.97959  79.93878  81.89796
[29]  83.85714  85.81633  87.77551  89.73469  91.69388  93.65306  95.61224
[36]  97.57143  99.53061 101.48980 103.44898 105.40816 107.36735 109.32653
[43] 111.28571 113.24490 115.20408 117.16327 119.12245 121.08163 123.04082
[50] 125.00000

So my task is to find the value of x when y=0. I couldn't find
guidance to use the xout function; any help with this please?

approxfun(x,y,rule=2,method="linear")
function (v)
.C("R_approx", as.double(x), as.double(y), as.integer(n), xout = as.double(v),
    as.integer(length(v)), as.integer(method), as.double(yleft),
    as.double(yright), as.double(f), NAOK = TRUE, PACKAGE = "base")$xout
<environment: 0x87e8830>

Where do I go to find out the meaning of these errors and how to resolve?

Yours,

rhelp at conference.jabber.org

r 251 (27-06-07)
mandriva 2008




More information about the R-help mailing list