sl.remap.array | R Documentation |
Remap a numeric array along one of its dimensions from an old to a new dimension variable vector.
sl.remap(input.data, input.dimvals, new.dimvals, remap.dim = 1, method = "linear", extrapolate.method = "none", return.remapinfo = FALSE, verbose = TRUE)
input.data |
a numeric array (can also be a vector or matrix) with |
input.dimvals |
a numeric vector of length |
new.dimvals |
a numeric vector of length |
remap.dim |
an integer for which |
method |
a character specifying the interpolation method. Must be one of |
extrapolate.method |
a character specifying the extrapolation method. Must be one of |
return.remapinfo |
a logical value specifying whether or not to return information on the remapping (nearest-neighbour-before indices and weights). Default is |
verbose |
a logical value specifying whether to produce warnings, in particular when the new dimension variable axis reaches outside the original dimension variable axis. Default is |
data |
an array with |
If return.remapinfo=TRUE
, an additional list element remapinfo
is returned, with the following sub-elements:
weights.left.ind |
an integer vector of length |
weights.left |
an numeric vector of length |
This function is similar to and was inspired by sl.trajectory.remaptime
but works on arrays (including vectors) instead of 1-dimensional spatial line objects on spheres (such as trajectories).
Helge Goessling
sl.trajectory.remaptime
# Vector remapping
x = seq(-2, 3, by=0.5)
y = x^2
x.remap = seq(-1, 5, by=0.3)
y.remap.lin = as.vector(sl.remap.array(input.dat=y, input.dimvals=x, new.dimvals=x.remap,
method="linear",extrapolate.method="linear")$data)
y.remap.nn = as.vector(sl.remap.array(input.dat=y, input.dimvals=x,new.dimvals=x.remap,
method="nearestneighbour",extrapolate.method="nearestneighbour")$data)
plot(x,y,ylim=c(0,20),type="p",xlim=c(-2,5))
points(x.remap,y.remap.lin,col="red")
points(x.remap,y.remap.nn,col="blue")
# Matrix remapping
dat1 = matrix(seq(0.5,3,by=0.5),ncol=3)
dat2 = sl.remap.array(input.dat=dat1, input.dimvals=1:3, new.dimvals = seq(1.5,3.5,by=0.5),
remap.dim=2, method="linear",extrapolate.method="linear")
print(dat1)
print(dat2$data)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.