Rev 47055 | 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-2008 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.}}\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}.}\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}