Create a matrix by giving row and column names and with all elements being set to a default value
Arguments
- rowNames
character vector of row names to be given to the matrix
- colNames
character vector of column names to be given to the matrix
- value
value to be given to each matrix element
- name.row
optional. Name to be given to the row dimension
- name.col
optional. Name to be given to the column dimension
Value
matrix with rowNames
as row names and colNames
as
column names, filled with value at each position
Examples
## Initialise a matrix with rows A to E and columns x to z of value -1
createMatrix(c("A", "B", "C", "D", "E"), c("x", "y", "z"), -1)
#> x y z
#> A -1 -1 -1
#> B -1 -1 -1
#> C -1 -1 -1
#> D -1 -1 -1
#> E -1 -1 -1
## By default the column names are assumed to be equal to the row names
createMatrix(c("A", "B", "C"))
#> A B C
#> A 0 0 0
#> B 0 0 0
#> C 0 0 0
## Initialise a square matrix with NA
createMatrix(c("A", "B", "C"), value = NA)
#> A B C
#> A NA NA NA
#> B NA NA NA
#> C NA NA NA
## Give a name to the row dimension
createMatrix(c("A", "B", "C"), name.row = "Letters")
#>
#> Letters A B C
#> A 0 0 0
#> B 0 0 0
#> C 0 0 0