array(data = NA, dim = length(data), dimnames = NULL)
as.array(x, ...)
is.array(x)
expression
vector) giving data to fill the array. Non-atomic classed objects
are coerced by as.vector
.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."dim"
) and optionally names for those
dimensions (attribute "dimnames"
). A two-dimensional array is the same thing as a matrix
.
One-dimensional 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 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 function.
For a list array, the print
methods prints entries of length
not one in the form integer,7 indicating the type and length.
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
Run the code above in your browser using DataLab