Hallo, I'm facing a problem and I would really appreciate your support. I have to translate some Matalb code in R that I don't know very well but I would like to. I have to interpolate 5 point with a cubic spline function and then I expect my function returns the Y value as output a specific X value inside the evaluation range. Let's suppose that: 1- *X = [-10, -5, 0, 5, 10]* 2 - *Y = [12, 10, 8, 7, 6]* 3 - *I have to interpolate with a cubic spline assuming x=11* In Matlab I used this function: *y = interp1(X, Y, x, "cubic"); * How can I do the same in R? Many thanks in advance for your reply and support! Kindly Steve -- View this message in context: http://r.789695.n4.nabble.com/cubic-spline-tp4651537.html Sent from the R help mailing list archive at Nabble.com.
Hi Steve, Check the "splint" function in the "fields" package. HTH, Jorge.- On Sat, Dec 1, 2012 at 11:09 PM, Steve Stephenson <> wrote:> Hallo, > I'm facing a problem and I would really appreciate your support. > I have to translate some Matalb code in R that I don't know very well but I > would like to. > I have to interpolate 5 point with a cubic spline function and then I > expect > my function returns the Y value as output a specific X value inside the > evaluation range. Let's suppose that: > 1- *X = [-10, -5, 0, 5, 10]* > 2 - *Y = [12, 10, 8, 7, 6]* > 3 - *I have to interpolate with a cubic spline assuming x=11* > > In Matlab I used this function: > > *y = interp1(X, Y, x, "cubic"); * > > How can I do the same in R? > Many thanks in advance for your reply and support! > Kindly > > Steve > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/cubic-spline-tp4651537.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > 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]]
Hi Jorge, many thanks for your suggestion! I tried the function you mentioned and it looks working!! Now I have just to check that splint (R) and interp1 (Matlab) functions provide me the same results. Kind regards! Steve -- View this message in context: http://r.789695.n4.nabble.com/cubic-spline-tp4651537p4651555.html Sent from the R help mailing list archive at Nabble.com.
On Dec 1, 2012, at 5:09 AM, Steve Stephenson wrote:> Hallo, > I'm facing a problem and I would really appreciate your support. > I have to translate some Matalb code in R that I don't know very > well but I > would like to. > I have to interpolate 5 point with a cubic spline function and then > I expect > my function returns the Y value as output a specific X value inside > the > evaluation range. Let's suppose that: > 1- *X = [-10, -5, 0, 5, 10]* > 2 - *Y = [12, 10, 8, 7, 6]* > 3 - *I have to interpolate with a cubic spline assuming x=11* > > In Matlab I used this function: > > *y = interp1(X, Y, x, "cubic"); * > > How can I do the same in R? > Many thanks in advance for your reply and support!splinefun( x = c(-10, -5, 0, 5, 10), y = c(12, 10, 8, 7, 6), method="natural")(11) [1] 5.785714 -- David Winsemius, MD Alameda, CA, USA