ArrayAround: Subset an Array with 4 dimensions

Description Usage Arguments Value Note Author(s) Examples

View source: R/gapfill.R

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

1
2
3
4
5
6
7
8
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.

Note

When size = c(0, 0, 0, 0), the returned subset consists of one value (the value of data indexed with mp.)
When mp is near the boundaries of data, the returned subset may be smaller than indicated by the argument size and the attribute mp may indicate an element near the boundaries of the subset.

Author(s)

Florian Gerber, flora.fauna.gerber@gmail.com.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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))

gapfill documentation built on Feb. 12, 2021, 5:06 p.m.