Learn R Programming

gapfill (version 0.9.6-1)

ArrayAround: Subset an Array with 4 dimensions

Description

Given an array data with 4 dimensions, a subset around the element with coordinates mp ("missing position") is extracted. The size of the subset in all four directions from mp is specified by size. ArrayAroundRandom returns a subset around a random location in data.

Usage

ArrayAround(data, mp, size)

ArrayAroundRandom( data, size = c(0L, 0L, 0L, 0L), target = c("all", "missing", "observed"), verbose = TRUE )

Arguments

data

Array with 4 dimensions.

mp

Integer vector of length 4 indexing an element in data.

size

Integer vector of length 4, that provides the size of the subset in all four dimensions (around mp).

target

One of c("all", "missing", "observed"). Indicates from which subset of data a random location is sampled.

verbose

Logical vector of length 1. If TRUE, messages are printed.

Value

Array with 4 dimensions corresponding to the specified subset. The attribute mp of the returned array is an integer vector of length 4 giving mp relative to the returned array.

Examples

Run this code
# NOT RUN {
a <- array(1:16, c(2, 2, 2, 2))
ArrayAround(data = a, mp = c(1, 1, 1, 1), size = c(0, 0, 0, 0))
## returns the first element a[1,1,1,1]

ArrayAround(data = a, mp = c(2, 2, 2, 2), size = c(0, 0, 0, 0))
## returns the last element a[2,2,2,2]

ArrayAround(data = a, mp = c(1, 1, 1, 1), size = c(1, 0, 0, 0))
## returns a[1:2,1,1,1]

ArrayAround(data = a, mp = c(1, 1, 1, 1), size = c(1, 1, 1, 1))
## returns a


ArrayAroundRandom(a)
ArrayAroundRandom(a, size = c(1, 2, 1, 2))
# }

Run the code above in your browser using DataLab