Learn R Programming

rje (version 1.4)

subtable: Subset an array

Description

More flexible calls of [ on an array.

Usage

subarray(x, value, drop = TRUE)
subtable(x, variables, value, drop = TRUE)

Arguments

x
An array.
variables
An integer vector containing the dimensions of x to subset.
value
A list or vector containing values to retain.
drop
Logical indicating whether dimensions with only 1 retained should be dropped. Defaults to TRUE.

Value

  • Returns an array of dimension sapply(value, length) if drop=TRUE, otherwise specified dimensions of size 1 are dropped. Dimensions which are unspecified in subtable are never dropped.

Details

Essentially just allows more flexible calls of [ on an array.

subarray requires the values for each dimension should be specified, so for a $2 \times 2 \times 2$ array x, subarray(x, list(1,2,1:2)) is just x[1,2,1:2].

subtable allows unspecified dimensions to be retained automatically. Thus, for example subtable(x, c(2,3), list(1, 1:2)) is x[,1,1:2].

See Also

Extract

Examples

Run this code
x = array(1:8, rep(2,3))
subarray(x, c(2,1,2)) == x[2,1,2]

x[2,1:2,2,drop=FALSE]
subarray(x, list(2,1:2,2), drop=FALSE)

subtable(x, c(2,3), list(1, 1:2))

Run the code above in your browser using DataLab