Arrays In R :-
As compared to matrices arrays have more than Two
dimensions . Adding a dim() attribute to an atomic vector
allows it to behave like a multi-dimensional array. A
special case of the array is the matrix, which has two
dimensions.
[Link]() function is used for creating arrays.
2. dim parameter given to array to specify its
dimensions .
3. arrays can have rows , columns and layers /levels
How to create array using array() in R studio :-
Syntax :-
array(data , dim=c(x,y,z……..))
Ex.1 Numeric Array
> arr=array(1:12,dim=c(2,2,3))
> arr
,,1 # 1st layer
[,1] [,2]
[1,] 1 3
[2,] 2 4
,,2 # 2nd layer
[,1] [,2]
[1,] 5 7
[2,] 6 8
,,3 # 3rd layer
[,1] [,2]
[1,] 9 11
[2,] 10 12
Ex. 2 Character Array of letters
> a1=array(letters[1:18],c(2,3,3))
> a1
,,1
[,1] [,2] [,3]
[1,] "a" "c" "e"
[2,] "b" "d" "f"
,,2
[,1] [,2] [,3]
[1,] "g" "i" "k"
[2,] "h" "j" "l"
,,3
[,1] [,2] [,3]
[1,] "m" "o" "q"
[2,] "n" "p" "r"
Commands On Array :-
1 . dim() :- Gives the no. of rows and columns and
levels in Array .
Ex.
> dim(a1)
[1] 2 3 3
2. length() :- Gives the total No. of elements in array.
Ex.
> length(a1)
[1] 18
3. names() :- it gives the names of dimensions of
array
Ex.
>array(1:12,c(2,2,3),dimnames=list(list("R1","R2"),list("C
1","C2"),list("L1","L2","L3")))
, , L1
C1 C2
R1 1 3
R2 2 4
, , L2
C1 C2
R1 5 7
R2 6 8
, , L3
C1 C2
R1 9 11
R2 10 12
> dimnames(a)
[[1]]
[1] "R1" "R2"
[[2]]
[1] "C1" "C2"
[[3]]
[1] "L1" "L2" "L3"
Thank You