Solved – Bicubic/bilinear interpolation in R

interpolationr

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

Best Answer

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.

Related Question