I need to perform an interpolation with R of (X,Y,Z) data: (X,Y) is a point on a plane, and Z is some property. Further I would like to plot data as a 3D surface using either scatterplot3d
, or rgl
, or plot3D
libraries. I want to use, as first solution, akima
library. The data come as a csv structure, where certain cells, either (XY) pair, or Z property are missing. Here is a minimal example:
data<-read.csv(text="lat,lon,T
40.075,50.096,84.2
40.263,50.549,82.2
,,73.6
40.328378,50.587409,84.8
39.856,50.435,,
40.1602,49.49,61.7")
(in this example lat and lon for X,Y are latitude and longitude, and T is temperature at certain depth). In some rows X,Y are missing, in some T lacks. The interpolation routine from akima
does not handle missing values, and feeding this data to it an error is produced.
library(akima)
s<-interp(data$x, data$y, data$T)
How it is possible either to drop missing data on the fly, or to perform an interpolation, maybe, using different routine which can be taught to ignore NA's?