| Line 14... |
Line 14... |
| 14 |
slice.index(x, MARGIN)
|
14 |
slice.index(x, MARGIN)
|
| 15 |
}
|
15 |
}
|
| 16 |
\arguments{
|
16 |
\arguments{
|
| 17 |
\item{x}{an array. If \code{x} has no dimension attribute, it is
|
17 |
\item{x}{an array. If \code{x} has no dimension attribute, it is
|
| 18 |
considered a one-dimensional array.}
|
18 |
considered a one-dimensional array.}
|
| 19 |
\item{MARGIN}{an integer giving the dimension number to slice by.}
|
19 |
\item{MARGIN}{an integer vector giving the dimension numbers to slice
|
| - |
|
20 |
by.}
|
| 20 |
}
|
21 |
}
|
| 21 |
\value{
|
22 |
\value{
|
| 22 |
An integer array \code{y} with dimensions corresponding to those of
|
23 |
An integer array \code{y} with dimensions corresponding to those of
|
| - |
|
24 |
\code{x}.
|
| - |
|
25 |
}
|
| - |
|
26 |
\details{
|
| - |
|
27 |
If \code{MARGIN} gives a single dimension, then all elements of slice
|
| 23 |
\code{x} such that all elements of slice number \code{i} with respect
|
28 |
number \code{i} with respect to this have value \code{i}. In general,
|
| - |
|
29 |
slice numbers are obtained by numbering all combinations of indices in
|
| - |
|
30 |
the dimensions given by \code{MARGIN} in column-major order. I.e.,
|
| - |
|
31 |
with \eqn{m_1}, \ldots, \eqn{m_k} the dimension numbers (elements of
|
| - |
|
32 |
\code{MARGIN}) sliced by and \eqn{d_{m_1}}, \ldots, \eqn{d_{m_k}} the
|
| - |
|
33 |
corresponding extents, and \eqn{n_1 = 1}, \eqn{n_2 = d_{m_1}}, \ldots,
|
| - |
|
34 |
\eqn{n_k = d_{m_1} \cdots d_{m_{k-1}}}{n_k = d_{m_1} \dots d_{m_{k-1}}},
|
| - |
|
35 |
the number of the slice where dimension \eqn{m_1} has value \eqn{i_1},
|
| 24 |
to dimension \code{MARGIN} have value \code{i}.
|
36 |
\ldots, dimension \eqn{m_k} has value \eqn{i_k} is
|
| - |
|
37 |
\eqn{1 + n_1 (i_1 - 1) + \cdots + n_k (i_k - 1)}{1 + n_1 (i_1 - 1) +
|
| - |
|
38 |
\dots + n_k (i_k - 1)}.
|
| 25 |
}
|
39 |
}
|
| 26 |
\seealso{
|
40 |
\seealso{
|
| 27 |
\code{\link{row}} and \code{\link{col}} for determining row and column
|
41 |
\code{\link{row}} and \code{\link{col}} for determining row and column
|
| 28 |
indexes; in fact, these are special cases of \code{slice.index}
|
42 |
indexes; in fact, these are special cases of \code{slice.index}
|
| 29 |
corresponding to \code{MARGIN} equal to 1 and 2, respectively when \code{x}
|
43 |
corresponding to \code{MARGIN} equal to 1 and 2, respectively when
|
| 30 |
is a matrix.
|
44 |
\code{x} is a matrix.
|
| 31 |
}
|
45 |
}
|
| 32 |
\examples{
|
46 |
\examples{
|
| 33 |
x <- array(1 : 24, c(2, 3, 4))
|
47 |
x <- array(1 : 24, c(2, 3, 4))
|
| 34 |
slice.index(x, 2)
|
48 |
slice.index(x, 2)
|
| - |
|
49 |
slice.index(x, c(1, 3))
|
| - |
|
50 |
## When slicing by dimensions 1 and 3, slice index 5 is obtained for
|
| - |
|
51 |
## dimension 1 has value 1 and dimension 3 has value 3 (see above):
|
| - |
|
52 |
which(slice.index(x, c(1, 3)) == 5, arr.ind = TRUE)
|
| 35 |
}
|
53 |
}
|
| 36 |
\keyword{array}
|
54 |
\keyword{array}
|