interp2xyz.RdFrom an interp() result, produce a 3-column matrix
or data.frame cbind(x, y, z).
interp2xyz(al, data.frame = FALSE)logical indicating if result should be data.frame or matrix (default).
a matrix (or data.frame) with three columns, called
"x", "y", "z".
expand.grid() is the “essential ingredient” of
interp2xyz().
data(akima)
ak.spl <- with(akima, interp(x, y, z, method = "akima"))
str(ak.spl)# list (x[i], y[j], z = <matrix>[i,j])
#> List of 3
#> $ x: num [1:40] 0 0.641 1.282 1.923 2.564 ...
#> $ y: num [1:40] 0 0.513 1.026 1.538 2.051 ...
#> $ z: num [1:40, 1:40] 58.2 55.3 52.4 49.5 46.7 ...
## Now transform to simple (x,y,z) matrix / data.frame :
str(am <- interp2xyz(ak.spl))
#> num [1:1600, 1:3] 0 0.641 1.282 1.923 2.564 ...
#> - attr(*, "dimnames")=List of 2
#> ..$ : NULL
#> ..$ : chr [1:3] "x" "y" "z"
str(ad <- interp2xyz(ak.spl, data.frame=TRUE))
#> 'data.frame': 1600 obs. of 3 variables:
#> $ x: num 0 0.641 1.282 1.923 2.564 ...
#> $ y: num 0 0 0 0 0 0 0 0 0 0 ...
#> $ z: num 58.2 55.3 52.4 49.5 46.7 ...
## and they are the same:
stopifnot( am == ad | (is.na(am) & is.na(ad)) )