How to create array using given columns, rows, and tables in R ?

• Last Updated : 24 Sep, 2021

In this article, we will discuss how to create an array using given columns, rows, and tables in R Programming Language. The array is created using the array() function.

Syntax: Array(vector.., dim=c(row, columns, tables))

Parameter:

• x: vector
• dim: values used to create array

Example 1: Creating a simple array with 2 rows, 3 columns, 1 table

The below example will create an array of 3×3 matrices with 1 table.

R

 `vector1 <- ``c``(0,1,2)``vector2 <- ``c``(3,4,5)` `data <- ``array``(``c``(vector1,vector2),dim = ``c``(2,3,1))``print``(data)`

Output:

```   [,1] [,2] [,3]
[1,]    0    2    4
[2,]    1    3    5```

The above array is created with 2 rows and 3 columns.

Example 2: Creating an array using 3 rows, 3 columns, and 2 tables.

Here we will create an array with 3 rows, 3 columns, and 2 tables.

R

 `vector1 <- ``c``(1:15)``vector2 <- ``c``(16:30)` `data <- ``array``(``c``(vector1,vector2),dim = ``c``(3,3,2))``print``(data)`

Output:

My Personal Notes arrow_drop_up