Z <- array(data_vector,dim_vector)
For example, if the vector h contains 24, or fewer, numbers then the command
Z <- array(h, dim=c(3,4,2))
would use h to set up
array in Z. If the
size of h is exactly 24 the result is the same as
dim(Z) <- c(3,4,2)
However if h is shorter than 24, its values recycled from the
beginning again to make it up to size 24. See §
below. As
an extreme but common example
Z <- array(0, c(3,4,2)
makes Z an array of all zeros.
At this point dim(Z) stands for the dimension vector c(3,4,2), and Z[1:24] stands for the data vector as it was in h, and Z[] with an empty subscript or Z with no subscript stands for the entire array as an array.
Arrays may be used in arithmetic expressions and the result is an array formed by element by element operations on the data vector. The dim attributes of operands generally need to be the same, and this becomes the dimension vector of the result. So if A, B and C are all similar arrays, then
D <- 2*A*B + C + 1
makes D a similar array with data vector the result of the evident element by element operations. However the precise rule concerning mixed array and vector calculations has to be considered a little more carefully.