An array in R is a data structure that can hold multi-dimensional data of the same type stored in a single variable.
To obtain the length of an array in R, we make use of the length()
function.
length(array)
The length()
function takes a single but mandatory parameter value that represents the array
object.
The length()
function returns the length of a given array.
# creating an array variablemyarray <- c(1:10)# creating a multidimensional array using the array() functionmultiarray <- array(myarray, dim = c(3,2))# to obtain the length of the array using the length functionlength(multiarray)
myarray
with its elements starting from 1
to 10
.array()
function, we create a 3x2 dimensional array multiarray
.length()
function, we check for the length of the array multiarray
.Note: The output of the code
6
is obtained from the dimensions of the array (3 * 2 = 6).