[R] How to predict/interpolate new Y given knwon Xs and Ys?

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Tue Jan 26 10:11:39 CET 2021


Hello,
I have a series of x/y and a model. I can interpolate a new value of x
using this model, but I get funny results if I give the y and look for
the correspondent x:
```
> x = 1:10
> y = 2*x+15
> model <- lm(y~x)
> predict(model, data.frame(x=7.5))
 1
30
> predict(model, data.frame(y=26))
 1  2  3  4  5  6  7  8  9 10
17 19 21 23 25 27 29 31 33 35
Warning message:
'newdata' had 1 row but variables found have 10 rows
> data.frame(x=7.5)
    x
1 7.5
> data.frame(y=26)
   y
1 26
```
what is the correct syntax?
Thank you
Luigi



More information about the R-help mailing list