[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  array: 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

data

a vector (including a list or ` [ expression
](/link/expression?package=base&version=3.6.2) ` vector) giving data to fill
the array. Non-atomic classed objects are coerced by ` [ as.vector
](/link/as.vector?package=base&version=3.6.2) ` .

dim

the dim attribute for the array to be created, that is an integer vector of
length one or more giving the maximal indices in each dimension.

dimnames

either ` NULL ` or the names for the dimensions. This must a list (or it will
be ignored) with one component for each dimension, either ` NULL ` or a
character vector of the length given by ` dim ` for that dimension. The list
can be named, and the list names will be used as names for the dimensions. If
the list is shorter than the number of dimensions, it is extended by ` NULL `
s to the length required.

x

an  R  object.

…

additional arguments to be passed to or from methods.

##  Value

` array ` returns an array with the extents specified in ` dim ` and naming
information in ` dimnames ` . The values in ` data ` are taken to be those in
the array with the leftmost subscript moving fastest. If there are too few
elements in ` data ` to fill the array, then the elements in ` data ` are
recycled. If ` data ` has length zero, ` NA ` of an appropriate type is used
for atomic vectors ( ` 0 ` for raw vectors) and ` NULL ` for lists.

Unlike ` [ matrix ](/link/matrix?package=base&version=3.6.2) ` , ` array `
does not currently remove any attributes left by ` as.vector ` from a classed
list ` data ` , so can return a list array with a class attribute.

` as.array ` is a generic function for coercing to arrays. The default method
does so by attaching a ` [ dim ](/link/dim?package=base&version=3.6.2) `
attribute to it. It also attaches ` [ dimnames
](/link/dimnames?package=base&version=3.6.2) ` if ` x ` has ` [ names
](/link/names?package=base&version=3.6.2) ` . The sole purpose of this is to
make it possible to access the ` dim[names] ` attribute at a later time.

` is.array ` returns ` TRUE ` or ` FALSE ` depending on whether its argument
is an array (i.e., has a ` dim ` attribute of positive length) or not. It is
generic: you can write methods to handle specific classes of objects, see [
InternalMethods ](/link/InternalMethods?package=base&version=3.6.2) .

##  Details

An array in  R  can have one, two or more dimensions. It is simply a vector
which is stored with additional [ attributes
](/link/attributes?package=base&version=3.6.2) giving the dimensions
(attribute ` "dim" ` ) and optionally names for those dimensions (attribute `
"dimnames" ` ).

A two-dimensional array is the same thing as a ` [ matrix
](/link/matrix?package=base&version=3.6.2) ` .

One-dimensional arrays often look like vectors, but may be handled differently
by some functions: ` [ str ](/link/str?package=base&version=3.6.2) ` does
distinguish them in recent versions of  R  .

The ` "dim" ` attribute is an integer vector of length one or more containing
non-negative values: the product of the values must match the length of the
array.

The ` "dimnames" ` attribute is optional: if present it is a list with one
component for each dimension, either ` NULL ` or a character vector of the
length given by the element of the ` "dim" ` attribute for that dimension.

` is.array ` is a [ primitive ](/link/primitive?package=base&version=3.6.2)
function.

For a list array, the ` print ` methods prints entries of length not one in
the form  integer,7  indicating the type and length.

##  References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988)