[R] Extrapolate x values from a defined y sequence

Eric Berger ericjberger @ending from gm@il@com
Mon Jan 14 14:02:33 CET 2019


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 using r-project.org> wrote:

> Hello,
> I have two sets of measurement :with the same x sequence
> :x1<-1:10y1<-c(5,4.6,4.4,4.2,4,3.8,3.7,3.6,3,1)
> x2<-1:10y2<-c(5,4.8,4.6,4.4,4.1,4,3.8,3.6,2.8,1)
> I would like to sum these two curves in terms of x for a given sequence of
> y (for example : y<-c(5,4.5,4,3.5,3,2.5,2,1.5,1)), that is to determine for
> each y, an x1' from x1 and an x2' from x2 corresponding to y so that I can
> plot y as a function of (x1'+x2').
> I hope it is clear enough.
> I think I can do it with a loop an some non-conventional R script (I'm not
> a computer scientist) but i'm pretty sure that there is an elegant way to
> do it with R.
> It will be very kind if someone can give me some R functions to do
> it.Thanks in advance,Ptit Bleu.
>
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list