array
Multi-Way Arrays

Description

Creates or tests for an array. Arrays are matrices and higher-dimensional generalizations of matrices.

Usage

array(data = NA, dim = length(data), dimnames = NULL)
is.array(x)
as.array(x, ...)
## Default S3 method:
as.array(x, ...)

Arguments

data a vector containing the data values for the array in the normal array order: the first subscript varies most rapidly and the last subscript varies least rapidly. Missing values (NAs) are allowed.
dim a vector giving the extent for each dimension. The dim attribute of the array.
dimnames a list giving the dimnames for the array. This must satisfy certain criteria. See the DETAILS section for more information.
x a vector.
... reserved arguments for future use.

Details

The array class of objects are those that have an attribute dim, which is a vector of integers whose product equals the length of data.
An array can also have an attribute dimnames. This is a list of length(dim) components, each of which is either of length zero, or a vector of character strings that gives the labels corresponding to the levels of the corresponding subscript in the array. Thus, length(dimnames(x)[[i]]) must equal either 0 or dim(x)[i].
as.array is generic. Only the default method is implemented at present.
Value
array returns an array with the same mode as data, the dimensionality described by dim, and the optional dimnames attribute. If data is too short to fill the specified array, the data is repeated until the array is filled. If data is too long to fit into the specified array, the data is truncated.
is.array returns TRUE if x is an array object (has a dim attribute); otherwise it returns FALSE.
as.array.default returns x, if x is an array; otherwise it returns a 1-dimensional array with data from x and a dim attribute equal to length(x).
See Also
dim, dimnames, length, list, Matrix, table, vector.
Examples
# creates a 2 by 4 by 3 array
newarray <- array(c(1:8, 11:18, 111:118), dim = c(2,4,3), 
      dimnames = list(c("r1", "r2"), NULL, c("c1", "c2", "c3")) )
is.array(newarray)
# [1] TRUE
as.array(newarray)
x <- runif(12)
names(x) <- as.character(1:12)
as.array.default(x)
Package base version 6.1.1-7
Package Index