library("broadcast")
x <- array(1:24, 2:4)
ndim(x)
## [1] 3
x <- list(
array(1:10, 10),
array(1:10, c(2, 5)),
array(c(letters, NA), c(3,3,3))
)
lst.ndim(x)
## [1] 1 2 3
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)
## x y
## a 0 2
## b 1 3ndim
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.