Arrays in R

An array can be considered as a multiply subscripted collection of data entries. This section provides details on the construction and manipulation of arrays.

Array indexing and subsections of an array

Individual elements of an array may be referenced by giving the name of the array followed by the subscripts in square brackets, separated by commas.

More generally, subsections of an array may be specified by giving a sequence of index vectors in place of subscripts; however if any index position is given an empty index vector, then the full range of that subscript is taken.

Continuing the previous example, a[2,,] is a 4 * 2 array with dimension vector c(4,2) and data vector containing the values

c(a[2,1,1], a[2,2,1], a[2,3,1], a[2,4,1],
a[2,1,2], a[2,2,2], a[2,3,2], a[2,4,2])

in that order. a[,,] stands for the entire array, which is the same as omitting the subscripts entirely and using a alone.

For any array, say Z, the dimension vector may be referenced explicitly as dim(Z) (on either side of an assignment).

Also, if an array name is given with just one subscript or index vector, then the corresponding values of the data vector only are used; in this case the dimension vector is ignored. This is not the case, however, if the single index is not a vector but itself an array, as we next discuss.