Skip to content
Prev 378178 / 398502 Next

Extrapolate x values from a defined y sequence

Hi Lionel,
Your choice of variable names is a bit odd (the roles of x and y seem to be
reversed from the usual.)
Assuming that you are looking for linear interpolation (in spite of the
subject of your email),
does the following give you what you need?

u1 <- approx(x=y1,y=x1,xout=y)
u2 <- approx(x=y2,y=x2,xout=y)
v   <- u1$y + u2$y

# At this point v is the sequence  x1+x2 and y is as you specified it.
# v
# [1]  2.00000  6.00000 11.00000 16.29167 17.75000 18.41667 18.94444
19.47222 20.00000
# y
# [1] 5.0 4.5 4.0 3.5 3.0 2.5 2.0 1.5 1.0

HTH,
Eric



On Mon, Jan 14, 2019 at 2:16 PM lionel sicot via R-help <
r-help at r-project.org> wrote: