| 2 |
r |
1 |
\name{array}
|
| 7782 |
hornik |
2 |
\alias{array}
|
|
|
3 |
\alias{as.array}
|
|
|
4 |
\alias{is.array}
|
| 2 |
r |
5 |
\title{Multi-way Arrays}
|
| 7782 |
hornik |
6 |
\description{
|
|
|
7 |
Creates or tests for arrays.
|
|
|
8 |
}
|
| 2 |
r |
9 |
\usage{
|
| 15805 |
ripley |
10 |
array(data = NA, dim = length(data), dimnames = NULL)
|
| 2 |
r |
11 |
as.array(x)
|
|
|
12 |
is.array(x)
|
|
|
13 |
}
|
| 10525 |
ripley |
14 |
\arguments{
|
| 28014 |
ripley |
15 |
\item{data}{a vector (including a list) giving data to fill the array.}
|
| 15805 |
ripley |
16 |
\item{dim}{the dim attribute for the array to be created, that is a
|
|
|
17 |
vector of length one or more giving the maximal indices in
|
|
|
18 |
each dimension.}
|
| 10525 |
ripley |
19 |
\item{dimnames}{the names for the dimensions. This is a list with one
|
| 15805 |
ripley |
20 |
component for each dimension, either NULL or a character vector of
|
| 10525 |
ripley |
21 |
the length given by \code{dim} for that dimension. The list can be
|
|
|
22 |
names, and the names will be used as names for the dimensions.}
|
|
|
23 |
\item{x}{an \R object.}
|
|
|
24 |
}
|
| 2 |
r |
25 |
\value{
|
| 7782 |
hornik |
26 |
\code{array} returns an array with the extents specified in \code{dim}
|
| 15805 |
ripley |
27 |
and naming information in \code{dimnames}. The values in \code{data} are
|
| 7782 |
hornik |
28 |
taken to be those in the array with the leftmost subscript moving
|
| 15805 |
ripley |
29 |
fastest. If there are too few elements in \code{data} to fill the array,
|
| 28014 |
ripley |
30 |
then the elements in \code{data} are recycled. If \code{data} has
|
|
|
31 |
length zero, \code{NA} of an appropriate type is used for atomic
|
|
|
32 |
vectors and \code{NULL} for lists.
|
| 2 |
r |
33 |
|
| 7782 |
hornik |
34 |
\code{as.array()} coerces its argument to be an array by attaching a
|
|
|
35 |
\code{\link{dim}} attribute to it. It also attaches
|
|
|
36 |
\code{\link{dimnames}} if \code{x} has \code{\link{names}}.
|
|
|
37 |
The sole purpose of this is to make it possible to access the
|
|
|
38 |
\code{dim}[names] attribute at a later time.
|
| 2 |
r |
39 |
|
| 7782 |
hornik |
40 |
\code{is.array} returns \code{TRUE} or \code{FALSE} depending on
|
| 20877 |
maechler |
41 |
whether its argument is an array (i.e., has a \code{dim} attribute)
|
| 23358 |
ripley |
42 |
or not. It is generic: you can write methods to handle
|
| 27625 |
ripley |
43 |
specific classes of objects, see \link{InternalMethods}.
|
| 2 |
r |
44 |
}
|
| 24300 |
ripley |
45 |
\references{
|
|
|
46 |
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)
|
|
|
47 |
\emph{The New S Language}.
|
|
|
48 |
Wadsworth \& Brooks/Cole.
|
|
|
49 |
}
|
| 2 |
r |
50 |
\seealso{
|
| 10525 |
ripley |
51 |
\code{\link{aperm}}, \code{\link{matrix}},
|
|
|
52 |
\code{\link{dim}}, \code{\link{dimnames}}.
|
| 2 |
r |
53 |
}
|
|
|
54 |
\examples{
|
|
|
55 |
dim(as.array(letters))
|
| 7495 |
maechler |
56 |
array(1:3, c(2,4)) # recycle 1:3 "2 2/3 times"
|
| 7501 |
tlumley |
57 |
# [,1] [,2] [,3] [,4]
|
|
|
58 |
#[1,] 1 3 2 1
|
|
|
59 |
#[2,] 2 1 3 2
|
| 2 |
r |
60 |
}
|
| 286 |
maechler |
61 |
\keyword{array}
|