slice.index {base} | R Documentation |
Slice Indexes in an Array
Description
Returns a matrix of integers indicating the number of their slice in a given array.
Usage
slice.index(x, MARGIN)
Arguments
x |
an array. If |
MARGIN |
an integer vector giving the dimension numbers to slice by. |
Details
If MARGIN
gives a single dimension, then all elements of slice
number i
with respect to this have value i
. In general,
slice numbers are obtained by numbering all combinations of indices in
the dimensions given by MARGIN
in column-major order. I.e.,
with , ...,
the dimension numbers (elements of
MARGIN
) sliced by and , ...,
the
corresponding extents, and
,
, ...,
,
the number of the slice where dimension
has value
,
..., dimension
has value
is
.
Value
An integer array y
with dimensions corresponding to those of
x
.
See Also
row
and col
for determining row and column
indexes; in fact, these are special cases of slice.index
corresponding to MARGIN
equal to 1 and 2, respectively when
x
is a matrix.
Examples
x <- array(1 : 24, c(2, 3, 4))
slice.index(x, 2)
slice.index(x, c(1, 3))
## When slicing by dimensions 1 and 3, slice index 5 is obtained for
## dimension 1 has value 1 and dimension 3 has value 3 (see above):
which(slice.index(x, c(1, 3)) == 5, arr.ind = TRUE)