vec2symMat | R Documentation |
It converts a vector into a symmetric matrix by filling up the elements into the lower triangle of the matrix.
vec2symMat(x, diag = TRUE, byrow = FALSE)
x |
A vector of numerics or characters |
diag |
Logical. If it is |
byrow |
Logical. If it is |
A symmetric square matrix based on column major
Mike W.-L. Cheung <mikewlcheung@nus.edu.sg>
matrix2bdiag
vec2symMat(1:6)
# [,1] [,2] [,3]
# [1,] 1 2 3
# [2,] 2 4 5
# [3,] 3 5 6
vec2symMat(1:6, diag=FALSE)
# [,1] [,2] [,3] [,4]
# [1,] 1 1 2 3
# [2,] 1 1 4 5
# [3,] 2 4 1 6
# [4,] 3 5 6 1
vec2symMat(letters[1:6])
# [,1] [,2] [,3]
# [1,] "a" "b" "c"
# [2,] "b" "d" "e"
# [3,] "c" "e" "f"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.