Examples for 'base::slice.index'


Slice Indexes in an Array

Aliases: slice.index

Keywords: array

### ** Examples

x <- array(1 : 24, c(2, 3, 4))
slice.index(x, 2)
, , 1

     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    1    2    3

, , 2

     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    1    2    3

, , 3

     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    1    2    3

, , 4

     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    1    2    3
slice.index(x, c(1, 3))
, , 1

     [,1] [,2] [,3]
[1,]    1    1    1
[2,]    2    2    2

, , 2

     [,1] [,2] [,3]
[1,]    3    3    3
[2,]    4    4    4

, , 3

     [,1] [,2] [,3]
[1,]    5    5    5
[2,]    6    6    6

, , 4

     [,1] [,2] [,3]
[1,]    7    7    7
[2,]    8    8    8
## When slicing by dimensions 1 and 3, slice index 5 is obtained for
## dimension 1 has value 1 and dimension 3 has value 3 (see above):
which(slice.index(x, c(1, 3)) == 5, arr.ind = TRUE)
     dim1 dim2 dim3
[1,]    1    1    3
[2,]    1    2    3
[3,]    1    3    3

[Package base version 4.2.3 Index]