apad {magic}R Documentation

Pad arrays

Description

Multidimensional pad for arrays of arbitrary dimension

Usage

apad(a, l, e = NULL, method = "ext", post = TRUE)

Arguments

a Array to be padded
l Amount of padding to add. If a vector, it is interpreted as the extra extent of a along each of its dimensions (standard recycling is used). If a scalar, interpret as the dimension to be padded, in which case the amount is given by argument l.
e If l is a scalar, amount of padding to add to dimension l.
method String, with three possibilities: ext, mirror, and rep.
The first, ext, uses a padding value given by the “nearest” element of a, as measured by the Manhattan metric.
The second, mirror, fills the array with alternate mirror images of a, and the third, rep, fills it with copies of a.
post Boolean, with default TRUE meaning to append to a and FALSE meaning to prepend.

Note

Function apad() does not work with arrays with dimensions of zero extent: what to pad it with? To pad with a particular value, use adiag().

The function works as expected with vectors, which are treated as one-dimensional arrays. See examples section.

Function apad() is distinct from adiag(), which takes two arrays and binds them together. Both functions create an array of the same dimensionality as their array arguments but with possibly larger extents. However, the functions differ in the values of the new array elements. Function adiag() uses a second array; function apad() takes the values from its primary array argument.

Author(s)

Robin K. S. Hankin

See Also

adiag

Examples


apad(1:10,4,method="mirror")

a <- matrix(1:30,5,6)

apad(a,c(4,4))
apad(a,c(4,4),post=FALSE)

apad(a,1,5)

apad(a,c(5,6),method="mirror")
apad(a,c(5,6),method="mirror",post=FALSE)

[Package magic version 1.3-24 Index]