0

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?

astrsk
  • 375
  • 6
  • 20
  • So you want the `interp()` to handle missing data? What happens if you just filter out junk rows with `filter()`? Are you losing important information? – InfiniteFlash Dec 22 '17 at 22:28
  • The original dataframe contains more columns, in particular, several columns with Z properties, and they sporadically are void. Creating a separate subset for interp() in each case might give completely different irregular grids for each of these cases, and this might impose additional artefacts on the resulting 3D surfaces (they will be poorly matching). Besides that, since there are many properties to interpolate (temperatures at depths 0.5, 1, 2, 3 km and so on) a unified batch solution is preferable. – astrsk Dec 22 '17 at 22:37
  • If all you need is to drop missing data, can you do `data[complete.cases(data),]`? – r2evans Dec 22 '17 at 22:46
  • 1
    This answer shows A: Plot 3D plane (true regression surface) . how to draw a regression surface which might be used to fill in the cases with missing T values. It would also construct a smooth span over interior gaps. It should not be extended outside the boundaries of the data however. The rms package has a method for restricting plotting to a perimeter around multivariate data. – IRTFM Dec 22 '17 at 23:03

0 Answers0