[R] order of points in spline

_nico_ romano.nicola at gmail.com
Fri Nov 6 20:40:57 CET 2009


Hello everyone,

I was trying to fit a spline to some points and I was quite surprised to
find out that the function spline does not take into account the order of
the points themselves, but orders them by x.

For instance, I have:
x <- c(262, 275, 264, 250, 247, 242, 238, 233)
y <- c(422, 389, 359, 308, 269, 229, 191, 176)
plot(x, y, xlim=c(0, 500), ylim=c(0,500))
s <- spline(x,y)
points(s, type="l", lwd=2)

As you can see from the above examplethe spline is fitted not using the
points in the order that was passed, but ordering them by x.

Is there a way to prevent this?
I also tried loess and other packages that fit curves to points but didn't
have any luck either

thanks
nico
-- 
View this message in context: http://old.nabble.com/order-of-points-in-spline-tp26230875p26230875.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list