Here we explain how to write an R program to create an array using four columns, three rows, and two tables. Here we are using a built-in functions array(),dim() for this. The dim() function helps retrieve or set the dimension of an object and the array() function helps create the array. The syntax of this function is
– where x is an R object like a matrix, array, or data frame
– where data is a vector giving data to fill the array
Below are the steps used in the R program to create an array using given four columns, three rows, and two tables. In this R program, we give the values directly to an array(),dim(). Here we are using variable A for holding the result array. Here we are creating an array using the given data. Finally, print the array.
A = array(1:30, dim=c(3,5,2))
print(A)
## , , 1
##
## [,1] [,2] [,3] [,4] [,5]
## [1,] 1 4 7 10 13
## [2,] 2 5 8 11 14
## [3,] 3 6 9 12 15
##
## , , 2
##
## [,1] [,2] [,3] [,4] [,5]
## [1,] 16 19 22 25 28
## [2,] 17 20 23 26 29
## [3,] 18 21 24 27 30
A = array(1:30, dim=c(5,3,2))
print(A)
## , , 1
##
## [,1] [,2] [,3]
## [1,] 1 6 11
## [2,] 2 7 12
## [3,] 3 8 13
## [4,] 4 9 14
## [5,] 5 10 15
##
## , , 2
##
## [,1] [,2] [,3]
## [1,] 16 21 26
## [2,] 17 22 27
## [3,] 18 23 28
## [4,] 19 24 29
## [5,] 20 25 30