How to create arrays in R language
In this article, the editor introduces in detail "how to create an array in R language". The content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to create an array in R language" can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.
Array is a generalization of vectors and matrices, which is multi-dimensional (three-dimensional or more) data. Like vectors and matrices, the elements of an array must be the same type of data. For example-if we create an array of dimensions (2dy3 and 4), we will create four rectangular matrices, each with two rows and three columns.
Create an array
In R, you usually use the array () function to create an array. The prototype of array () is:
Array (data = NA, dim = length (data), dimnames = NULL)
Where: data given array elements, by default is the dimension that NA;dim uses to specify the array, by default is an one-dimensional array; dimnames sets the name of each dimension, which must be a list, and there is no name by default.
For example, create an array of two 3x3 matrices, each with three rows and three columns.
# Create two vectors of different lengths.vector1