Arrays are the R data objects which can store data in more than two dimensions. For example: If we create an array of dimensions (2, 3, 4) then it creates 4 rectangular matrices each with 2 rows and 3 columns. These types of arrays are called Multidimensional Arrays. Arrays can store only data types.
Creating a Multidimensional Array
An array is created using the
array() function. It takes vectors as input and uses the values in the dim parameter to create an array. A multidimensional array can be created by defining the value of ‘dim‘ argument as the number of dimensions that are required.
MArray = array(c(vec1, vec2), dim)
, , 1 [,1] [,2] [,3] [1,] 5 10 13 [2,] 9 11 14 [3,] 3 12 15 , , 2 [,1] [,2] [,3] [1,] 5 10 13 [2,] 9 11 14 [3,] 3 12 15
Naming Columns and Rows
We can give names to the rows, columns, and matrices in the array by using the
, , Matrix1 COL1 COL2 COL3 ROW1 5 10 13 ROW2 9 11 14 ROW3 3 12 15 , , Matrix2 COL1 COL2 COL3 ROW1 5 10 13 ROW2 9 11 14 ROW3 3 12 15
Manipulating Array Elements
As the array is made up of matrices in multiple dimensions, the operations on elements of the array are carried out by accessing elements of the matrices. There are various different Operations can be performed on Arrays.
[,1] [,2] [,3] [1,] 10 20 26 [2,] 18 22 28 [3,] 6 24 30
- PHP multidimensional array search by value
- How to search by key=>value in a multidimensional array in PHP ?
- Sort a multidimensional array by date element in PHP
- How to check an array is multidimensional or not in PHP ?
- How to merge the duplicate value in multidimensional array in PHP ?
- Multidimensional Associative Array in PHP
- Multidimensional Arrays in Java
- Multidimensional arrays in PHP
- Perl | Multidimensional Hashes
- Perl | Multidimensional Arrays
- Array.BinarySearch(Array, Object) Method with examples in C#
- Array.BinarySearch(Array, Int32, Int32, Object) Method with examples in C#
- What is the difference between array_merge and array + array in PHP?
- How to sort an Array in C# | Array.Sort() Method Set – 2
- Copy an Array by Value and Reference into Another Array in Golang
- How to merge the first index of an array with the first index of second array?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.