Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

ndims

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

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

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.