array
Multiway Arrays
Creates or tests for arrays.
 Keywords
 array
Usage
array(data = NA, dim = length(data), dimnames = NULL)
as.array(x, ...)
is.array(x)
Arguments
 data
 a vector (including a list or
expression
vector) giving data to fill the array. Nonatomic classed objects are coerced byas.vector
.  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, eitherNULL
or a character vector of the length given bydim
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 byNULL
s to the length required.  x
 an R object.
 ...
 additional arguments to be passed to or from methods.
Details
An array in R can have one, two or more dimensions. It is simply a
vector which is stored with additional attributes giving the
dimensions (attribute "dim"
) and optionally names for those
dimensions (attribute "dimnames"
).
A twodimensional array is the same thing as a matrix
.
Onedimensional arrays often look like vectors, but may be handled
differently by some functions: str
does distinguish
them in recent versions of R.
The "dim"
attribute is an integer vector of length one or more
containing nonnegative 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 function.
For a list array, the print
methods prints entries of length
not one in the form integer,7 indicating the type and length.
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, 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 attribute to
it. It also attaches dimnames if x has
names. 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.
Note
is.array
is a primitive function.
R 2.x.y allowed (although documented not to) a zerolength dim
argument, and returned a vector of length one.
References
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
See Also
Examples
library(base)
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
Community examples
Examples for [LinkedIn Learning: R for Data Science, Lunchbreak Lessons](https://linkedinlearning.pxf.io/rweekly_array) ```r # array is a vector or list with 2+ dimensions # (Matrix is a 2dimension Array. Array is like stacked matrices) I.am.a.vector < c("twas","brillig","and","the","slithey","toves","did","gyre","and","gimble","in","wabe") # array(data_vector,dim_vector) # dimension is expressed as row, column, zindex I.am.an.array < array(I.am.a.vector,c(2,3,2)) I.am.an.array # indexing into the array I.am.an.array[2,3,3] # this fails because there is not a third level I.am.an.array[2,3,2] I.am.an.array[2,3,2] < "a new value" I.am.an.array[2,,2] # omission returns the entire range. Here  all columns of row 2, table 2 # dimnames my.row.names < c("up","down") my.column.names < c("left","middle","right") my.table.names < c("behind","in front") dimnames(I.am.an.array) < list(my.row.names,my.column.names,my.table.names) I.am.an.array I.am.an.array["down",3,2] ```