How to find points by linear interpolation
I suggest make a function that solves for y = mx + b.
x = c(5,6)
y = c(0.45, 0.50)
m <- (y[2] - y[1]) / (x[2] - x[1]) # slope formula
b <- y[1]-(m*x[1]) # solve for b
m*(5.019802) + b
# same answer as the approx function
[1] 0.4509901
You just need to specify an xout
value.
approx(x,y,xout=5.019802)
$x
[1] 5.019802
$y
[1] 0.4509901