简体   繁体   中英

how can I count the number of layer of 3D array in R?

If 3D array a is defined as below,

a <- rep(NA,200)
a <- array(data = a, dim = c(10,10,2))

a consists of 2 layers of a 10 (column)*10 (row) matrix. I know that I can use ncol or nrow for counting column and row of each layer of a . in this case I can simply count manually the number of layers of a , because it has just 2 layers of data; but for the case when the number of layers a is much larger (such as 200 or 2000, not just 2), then I cannot count manually how many layers a has.

So I wonder if there is a function which counts the number of layers of a 3D array in R.

Can anyone help me with this?

We use dim to find the dimensions.

dim(a)

According to ?dim

 For an array (and hence in particular, for a matrix) 'dim' retrieves the 'dim' attribute of the object. It is 'NULL' or a vector of mode 'integer'. 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM