R Array Data Types: Creation Guide
To create an array of a specific data type in R language, you can use the array() function. The basic syntax of this function is as follows:
array(data, dim = NULL, dimnames = NULL)
In this case, data refers to the data that will be stored in the array, dim is an integer vector specifying the dimensions of the array, and dimnames is a list containing the names of the dimensions.
For example, to create a 3-dimensional array of integer type, you can use the following code:
my_array <- array(data = c(1, 2, 3, 4, 5, 6), dim = c(2, 3, 1))
This will create an integer array called my_array with dimensions 2x3x1, storing consecutive integers from 1 to 6. Elements in the array can be accessed using indexes, for example my_array[1, 2, 1] will return the element in the first row and second column of the array.