6
$\begingroup$

I have a data set of x,y,z data and I'd like to do a bicubic interpolation. x and y are spatial coordinates and z is a temperature.

Below there are two images. The first one is a (gnuplot) plot of my dataset and the second one is an interpolated version (set pm3d interpolate 10,10).

Now I'd like to do this interpolation in R but I want a matrix of values as result and not a plot. The climates package seemed to provide this in R, but it does not work in R 2.13 anymore.

Is there another way/package to interpolate in R the way I want?

enter image description here enter image description here

$\endgroup$
5
$\begingroup$

Check out the akima package's interp.

These functions implement bivariate interpolation onto a grid for irregularly spaced input data. Bilinear or bicubic spline interpolation is applied using different versions of algorithms from Akima.

Usage

interp(x, y, z, xo=seq(min(x), max(x), length = 40), yo=seq(min(y), max(y), length = 40), linear = TRUE, extrap=FALSE, duplicate = "error", dupfun = NULL, ncp = NULL)

I assume it will work if your data is regularly spaced as well.

$\endgroup$
  • $\begingroup$ This worked fine within R. I still have problems on how to export the data in x,y,z notation. I'd appreciate if someone could comment on this $\endgroup$ – Martin H Oct 7 '11 at 16:54
  • 2
    $\begingroup$ I believe something like i <- interp (x, y, z) followed by c <- cbind (expand.grid (i$x, i$y), c(i$z)) and if you want nice names colnames (c) <- c("x", "y", "z") is close. I might have gotten the x and y reversed, so check that. $\endgroup$ – Wayne Oct 7 '11 at 17:33
  • $\begingroup$ the expand.grip function did the trick. I still don't quite understand the meaning of it but I will try to give it a read. $\endgroup$ – Martin H Oct 10 '11 at 8:05
0
$\begingroup$

You could use image.smooth in the fields package.

$\endgroup$
  • 2
    $\begingroup$ Judging by the name, that's probably doing smoothing, not interpolation - the difference being whether the original points are preserved exactly, or not. $\endgroup$ – Ken Williams Dec 17 '12 at 16:49
-1
$\begingroup$

To export the data you have interpolated , you could use the follow way:

model <- interp(x, y, z, xo=seq(min(x), max(x), length = 40), yo=seq(min(y),
    max(y), length = 40), linear = TRUE, extrap=FALSE, duplicate = "error", 
    dupfun = NULL, ncp = NULL)
interpData <- model$z

Load the follow libraries

library(rJava)
library(xlsxjars)
library(xlsx)

Export your interpolated data in Excel with title multivariateInterp in your hard disc

write.xlsx (interpData, "c:/multivariateInterp.xlsx")
$\endgroup$
  • $\begingroup$ Uncertain whether the question was modified, but at the moment this answer does not address the question. Please modify $\endgroup$ – Mikko Oct 21 '18 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.