An array in R is simply a data structure that can hold multi-dimensional data of the same type in a single variable. The array object can hold data of two or more dimensions.
To obtain the dimension of an array in R, we use the dim()
function.
dim(array)
The dim()
function takes a single parameter value that represents the array object.
The dim()
function returns the dimension of the array object.
# creating an array variablemyarray <- c(1:10)# creating a multidimensional arraymultiarray <- array(myarray, dim = c(3,2))# using the dim() function to obtain the dimension of the arraydim(multiarray)
myarray
with its elements ranging from 1 to 10.array()
function, we create a 3
by 2
dimensional array.dim()
function, we check for the dimension of the array multiarray
.Note: The output of the code above (
3 2
) simply means that the array is a 3 by 2 array.