row
and
col
functions: row(x) can be expressed as
slice.index(x,1) and col(x) can be expressed as slice.index(x,2).
slice.index(x, MARGIN)
x
has no dimensions it will be considered to be
a one dimensional array.
x
.
The subarray
result[...,i,...]
, where
i
is the
MARGIN
th dimension will
be filled with the value
i
.
In the future this function may be extended to allow a vector
of integers for the
MARGIN
argument, as in the
apply
function.
x <- array(data=101:124, dim=c(4, 3, 2)) slice.index(x, 1) # Produces the following output: # , , 1 # [,1] [,2] [,3] # [1,] 1 1 1 # [2,] 2 2 2 # [3,] 3 3 3 # [4,] 4 4 4 # , , 2 # [,1] [,2] [,3] # [1,] 1 1 1 # [2,] 2 2 2 # [3,] 3 3 3 # [4,] 4 4 4 slice.index(x,3) # Produces the following output: # , , 1 # [,1] [,2] [,3] # [1,] 1 1 1 # [2,] 1 1 1 # [3,] 1 1 1 # [4,] 1 1 1 # , , 2 # [,1] [,2] [,3] # [1,] 2 2 2 # [2,] 2 2 2 # [3,] 2 2 2 # [4,] 2 2 2 split(x, group=slice.index(x, 2)) # compare to x[,1,], x[,2,], x[,3,] # Produces the following output: # $"1": # [1] 101 102 103 104 113 114 115 116 # $"2": # [1] 105 106 107 108 117 118 119 120 # $"3": # [1] 109 110 111 112 121 122 123 124