diag3Darray | R Documentation |
Define function to create a 'diagonal' array or get the diagonal of an array
diag3Darray(x = 1, dim = length(x), out = "vector")
x |
|
dim |
|
out |
|
The diagonal of a 3D array has been defined as those elements in positions c(int,int,int), i.e., the three digits are the same.
If the diagonal should be returned, out
specifies if it should return a "vector"
with
the elements of position c(int,int,int), or "matrix"
with the elements of position c(int,dim,int),
i.e., dim = 2
-> elements (1,1,1),(2,1,2),(3,1,3),(1,2,1),(2,2,2),(3,2,3),(3,1,3),(3,2,3),(3,3,3).
array
with all elements zero except the diagonal, with dimensions c(dim,dim,dim)
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.