Rev 49852 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/array.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2010 R Core Development Team% Distributed under GPL 2 or later\name{array}\alias{array}\alias{as.array}\alias{as.array.default}\alias{is.array}\title{Multi-way Arrays}\description{Creates or tests for arrays.}\usage{array(data = NA, dim = length(data), dimnames = NULL)as.array(x, ...)is.array(x)}\arguments{\item{data}{a vector (including a list) giving data to fill the array.}\item{dim}{the dim attribute for the array to be created, that is avector of length one or more giving the maximal indices ineach dimension.}\item{dimnames}{either \code{NULL} or the names for thedimensions. This is a list with one component for each dimension,either \code{NULL} or a character vector of the length given by\code{dim} for that dimension. The list can be named, and the list nameswill be used as names for the dimensions. If the list is shorterthan the number of dimensions, it is extended by \code{NULL}s to thelength required}\item{x}{an \R object.}\item{\dots}{additional arguments to be passed to or from methods.}}\details{An array in \R can have one, two or more dimensions. It is simply avector which is stored with additional \link{attributes} giving thedimensions (attribute \code{"dim"}) and optionally names for thosedimensions (attribute \code{"dimnames"}).A two-dimensional array is the same thing as a \code{\link{matrix}}.One-dimensional arrays often look like vectors, but may be handleddifferently by some functions: \code{\link{str}} does distinguishthem in recent versions of \R.The \code{"dim"} attribute is an integer vector of length one or morecontaining non-negative values: the product of the values must matchthe length of the array.The \code{"dimnames"} attribute is optional: if present it is a listwith one component for each dimension, either \code{NULL} or acharacter vector of the length given by the element of the\code{"dim"} attribute for that dimension.}\value{\code{array} returns an array with the extents specified in \code{dim}and naming information in \code{dimnames}. The values in \code{data} aretaken to be those in the array with the leftmost subscript movingfastest. If there are too few elements in \code{data} to fill the array,then the elements in \code{data} are recycled. If \code{data} haslength zero, \code{NA} of an appropriate type is used for atomicvectors (\code{0} for raw vectors) and \code{NULL} for lists.\code{as.array} is a generic function for coercing to arrays. Thedefault method does so by attaching a \code{\link{dim}} attribute toit. It also attaches \code{\link{dimnames}} if \code{x} has\code{\link{names}}. The sole purpose of this is to make it possibleto access the \code{dim[names]} attribute at a later time.\code{is.array} returns \code{TRUE} or \code{FALSE} depending onwhether its argument is an array (i.e., has a \code{dim} attribute ofpositive length) or not. It is generic: you can write methods to handlespecific classes of objects, see \link{InternalMethods}.}\note{\code{is.array} is a \link{primitive} function so any argument name isignored.}\references{Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)\emph{The New S Language}.Wadsworth & Brooks/Cole.}\seealso{\code{\link{aperm}}, \code{\link{matrix}},\code{\link{dim}}, \code{\link{dimnames}}.}\examples{dim(as.array(letters))array(1:3, c(2,4)) # recycle 1:3 "2 2/3 times"# [,1] [,2] [,3] [,4]#[1,] 1 3 2 1#[2,] 2 1 3 2}\keyword{array}