array {base} | R Documentation |
Creates or tests for arrays.
array(data = NA, dim = length(data), dimnames = NULL)
as.array(x)
is.array(x)
data |
a vector giving data to fill the array. |
dim |
the dim attribute for the array to be created, that is a vector of length one or more giving the maximal indices in each dimension. |
dimnames |
the names for the dimensions. This is a list with one
component for each dimension, either NULL or a character vector of
the length given by |
x |
an R object. |
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.
as.array()
coerces its argument to be an array 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)
or not.
aperm
, matrix
,
dim
, dimnames
.
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