pad_array {lacunr}R Documentation

Add padding to 3D array

Description

pad_array() adds additional rows, columns, or slices to a 3-dimensional array, increasing the array's dimensions by the desired amount and filling the new space with a uniform value. It is intended for adding empty or occupied space to the edges of a 3D spatial map.

Usage

pad_array(a, x = 0, y = 0, z = 0, fill = 0)

Arguments

a

A 3-dimensional array of numeric values

x

A positive or negative integer, denoting the number of rows to add to the array. The sign dictates which side of the array to pad. Default is zero.

y

A positive or negative integer, denoting the number of columns to add to the array. The sign dictates which side of the array to pad. Default is zero.

z

A positive or negative integer, denoting the number of "slices" to add to the array. The sign dictates which side of the array to pad. Default is zero.

fill

The desired value to fill the array padding with. Default is zero.

Details

pad_array() uses the signs of x, y, and z to determine where to add padding. Negative values are prepended before the array's lower indices (what one might call the "top", "front", or "beginning" of the array), while positive values are appended after the upper indices (the "bottom", "back", or "end" of the array).

Value

A 3-dimensional array with the desired padding added. The padded portions are labelled using their dimnames. If no padding has been specified, the function returns the original array.

Examples

# generate array
a <- array(data = rep(c(1,0), 125), dim = c(5,5,5))
# add two rows of zeroes to top of array
pad <- pad_array(a, x = -2)
# add one row of zeroes to bottom of array, and two columns to beginning
pad <- pad_array(a, x = 1, y = -2)


[Package lacunr version 1.0.1 Index]