Skip to contents

ndims(x) is short-hand for length(dim(x)).

Usage

ndims(x)

Arguments

x

the object to get the number of dimensions from.

Value

An integer, giving the number of dimensions x has.

For vectors, gives 0L.


Examples


x <- 1:10
ndims(x)
#> [1] 0
obj <- array(1:64, c(4,4,3))
print(obj)
#> , , 1
#> 
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    5    9   13
#> [2,]    2    6   10   14
#> [3,]    3    7   11   15
#> [4,]    4    8   12   16
#> 
#> , , 2
#> 
#>      [,1] [,2] [,3] [,4]
#> [1,]   17   21   25   29
#> [2,]   18   22   26   30
#> [3,]   19   23   27   31
#> [4,]   20   24   28   32
#> 
#> , , 3
#> 
#>      [,1] [,2] [,3] [,4]
#> [1,]   33   37   41   45
#> [2,]   34   38   42   46
#> [3,]   35   39   43   47
#> [4,]   36   40   44   48
#> 
ndims(obj)
#> [1] 3