Pavel Shliaha Pavel Shliaha - 11 days ago 8
R Question

a model that simply returns y value based on closest x and y values

I have a set of data for x (x1) and y (y1). I need to get a new set of data with defined x (x2) values (so I need to find corresponding y values(y2)). For every x2 I want the model to find two x1 points between which x2 is, and then connect them with a straight line and find the corresponding y2.

Basically I want to build a plot through x1 and y1 points, where they are connceted with straight lines and then do a procedure analogous to extracting values from this plot.

G5W G5W
Answer

Alternatively,

f = approxfun(x,y)

Should do what you want.