The print_matrix()
function prints a (possibly
abbreviated) matrix
:
print_matrix(x = 1, label = "single numeric")
#> single numeric : 1
print_matrix(x = LETTERS[1:26], label = "letters")
#> letters : character vector of length 26
#> A B C ... Z
print_matrix(x = 1:3, coldots = 2)
#> double vector of length 3
#> 1 ... 3
print_matrix(x = matrix(rnorm(99), ncol = 1), label = "single column matrix")
#> single column matrix : 99 x 1 matrix of doubles
#> [,1]
#> [1,] 0.88
#> [2,] 0.38
#> [3,] 0.39
#> ... ...
#> [99,] -0.11
print_matrix(x = matrix(1:100, nrow = 1), label = "single row matrix")
#> single row matrix : 1 x 100 matrix of doubles
#> [,1] [,2] [,3] ... [,100]
#> [1,] 1 2 3 ... 100
print_matrix(x = matrix(LETTERS[1:24], ncol = 6), label = "big matrix")
#> big matrix : 4 x 6 matrix of characters
#> [,1] [,2] [,3] ... [,6]
#> [1,] A E I ... U
#> [2,] B F J ... V
#> [3,] C G K ... W
#> [4,] D H L ... X
print_matrix(x = diag(5), coldots = 2, rowdots = 2, simplify = TRUE)
#> [ 1 ... 0; ... ... ...; 0 ... 1 ]
The matrix_indices()
function returns matrix indices as
character
:
The insert_matrix_column()
function can add a column to
a matrix
:
A <- diag(3)
x <- numeric(3)
insert_matrix_column(A, x, 0)
#> [,1] [,2] [,3] [,4]
#> [1,] 0 1 0 0
#> [2,] 0 0 1 0
#> [3,] 0 0 0 1
insert_matrix_column(A, x, 1)
#> [,1] [,2] [,3] [,4]
#> [1,] 1 0 0 0
#> [2,] 0 0 1 0
#> [3,] 0 0 0 1
insert_matrix_column(A, x, 2)
#> [,1] [,2] [,3] [,4]
#> [1,] 1 0 0 0
#> [2,] 0 1 0 0
#> [3,] 0 0 0 1
insert_matrix_column(A, x, 3)
#> [,1] [,2] [,3] [,4]
#> [1,] 1 0 0 0
#> [2,] 0 1 0 0
#> [3,] 0 0 1 0