ndims: Number of Dimensions

View source: R/size.R

ndimsR Documentation

Number of Dimensions

Description

Number of matrix or array dimensions.

Usage

ndims(x)

Arguments

x

a vector, matrix, array, or list

Details

Returns the number of dimensions as length(x).

For an empty object its dimension is 0, for vectors it is 1 (deviating from MATLAB), for matrices it is 2, and for arrays it is the number of dimensions, as usual. Lists are considered to be (one-dimensional) vectors.

Value

the number of dimensions in a vector, matrix, or array x.

Note

The result will differ from Matlab when x is a vector.

See Also

size

Examples

ndims(c())                      # 0
ndims(as.numeric(1:8))          # 1
ndims(list(a=1, b=2, c=3))      # 1
ndims(matrix(1:12, 3, 4))       # 2
ndims(array(1:8, c(2,2,2)))     # 3

pracma documentation built on Nov. 10, 2023, 1:14 a.m.