x <- diag3Darray(c(1,4,6), dim = 3)
x
# , , 1
#
# [,1] [,2] [,3]
# [1,] 1 0 0
# [2,] 0 0 0
# [3,] 0 0 0
#
# , , 2
#
# [,1] [,2] [,3]
# [1,] 0 0 0
# [2,] 0 4 0
# [3,] 0 0 0
#
# , , 3
#
# [,1] [,2] [,3]
# [1,] 0 0 0
# [2,] 0 0 0
# [3,] 0 0 6
diag3Darray(x)
# 1, 4, 6
Run the code above in your browser using DataLab