ndim: Get the Number of Dimensions of an Array

View source: R/ndim.R

ndimR Documentation

Get the Number of Dimensions of an Array

Description

ndim() returns the number of dimensions of an object.
lst.ndim() returns the number of dimensions of every list-element.

Usage

ndim(x)

lst.ndim(x)

Arguments

x

a vector or array (for ndim()), or a list of vectors/arrays (for lst.ndim()).

Value

For ndim(): an integer scalar.
For lst.ndim(): an integer vector, with the same length, names and dimensions as x.

Examples


x <- array(1:24, 2:4)
ndim(x)

x <- list(
  array(1:10, 10),
  array(1:10, c(2, 5)),
  array(c(letters, NA), c(3,3,3))
)
lst.ndim(x)

x <- list(
  1:10,
  array(1:10, 10),
  matrix(1:10, 2, 5),
  array(c(letters, NA), c(3,3,3))
)
dim(x) <- c(2,2)
dimnames(x) <- list(c("a", "b"), c("x", "y"))
lst.ndim(x)



broadcast documentation built on Aug. 20, 2026, 9:08 a.m.

Related to ndim in broadcast...