R Arrays

An array is multi combination of data entries. The array function creates n dimensional array.
We can also create array using as.array function.
This is least used data type in R.

> A <- array(1:8, dim = c(2, 2, 2)) > class(A) [1] "array" > is.array(A) [1] TRUE > A , , 1 [,1] [,2] [1,] 1 3 [2,] 2 4 , , 2 [,1] [,2] [1,] 5 7 [2,] 6 8 > A[1,,] #Retrives first row each element [,1] [,2] [1,] 1 5 [2,] 3 7 > A[1,,1] # First row of first element [1] 1 3 > A[1,,2] # First row of Second element [1] 5 7 > A[2,,1] # Second row of first element [1] 2 4 > A[,,1] # Entire element of First element [,1] [,2] [1,] 1 3 [2,] 2 4

Powered by WordPress