approx2 | R Documentation |
Resample the (potentially scattered) 2D data to a rectilinear grid at the specified coordinates. Interpolation can be performed within a tolerance using several interpolation methods.
approx2(x, y, z, xout, yout,
interp = "linear", nx = length(x), ny = length(y),
tol = NA_real_, tol.ref = "abs", extrap = NA_real_)
x , y , z |
The data to be interpolated. Alternatively, |
xout , yout |
The coordinate (grid lines) where the resampling should take place. These are expanded into a rectilinear grid using |
interp |
Interpolation method. One of 'none', 'sum', 'mean', 'max', 'min', 'area', 'linear', 'cubic', 'gaussian', or 'lanczos'. |
nx , ny |
If |
tol |
The tolerance for the data points used for interpolation. Must be nonnegative. May be length-2 to have different tolerances for |
tol.ref |
If 'abs', then comparison is done by taking the absolute difference. If 'x', then relative differences are used. |
extrap |
The value to be returned when performing extrapolation, i.e., in the case when there is no data within |
See approx1
for details of the 1D implementation. The 2D implementation is mostly the same, except it uses a kd-tree to quickly find neighboring points.
Note that interp = "linear"
and interp = "cubic"
use a kernel-based approximation. Traditionally, bilinear and bicubic interpolation use 4 and 16 neighboring points, respectively. However, to support scattered data, approx2
will use as many points as are found within the given tolerance, and scale the kernels accordingly. If the input data falls on a regular grid already, then the tolerance should be specified accordingly. Set tol
equal to the sampling rate for interp = "linear"
and twice the sampling rate for interp = "cubic"
.
A vector of the same length as xout
, giving the resampled data.
Kylie A. Bemis
expand.grid
,
asearch
,
approx
,
approx1
x <- matrix(1:25, nrow=5, ncol=5)
approx2(x, nx=10, ny=10, interp="cubic") # upsampling
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.