Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create arrays in R language

Shulou Source: shulou.com Published: 2022-06-02 01:12:53 10月05日 Update

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

Tags: Array element matrix code result output run function dimension language name situation data article content parameter vector 3D proper two Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Linux Docker Shulou Technology Redmi