[R] Interpolate? a line

Michael Bedward michael.bedward at gmail.com
Wed Sep 15 12:52:45 CEST 2010


Hello Alex,

Here is one way to do it. It works but it's not pretty :)

interp <- approx(c(2, 62), c(3, 34), method="linear", xout=2:62)
m <- matrix(c(interp$x, round(interp$y)), ncol=2)
tie <- m[,2] == c(-Inf, m[-nrow(m),2])
m <- m[ !tie, ]

You might want to examine the result like this...

plot(m)  # plots points
lines(c(2,26), c(3, 34))  # overlay line for comparison

Michael



More information about the R-help mailing list