validation-matrix_dimensions | R Documentation |
Functions to check whether a matrix-like object has expected dimension numbers or names.
validMatDims(mat, nrow = NULL, ncol = NULL)
validMatDimnames(
mat,
row.names = NULL,
col.names = NULL,
dup.rownames = FALSE,
dup.colnames = FALSE
)
mat |
A matrix-like object |
nrow |
Expect how many rows in 'mat'. |
ncol |
Expect how many columns in 'mat'. |
row.names |
Expected row names for 'mat'. |
col.names |
Expected column names for 'mat'. |
dup.rownames , dup.colnames |
Whether or not to allow duplicated dimension names in 'mat'. |
If all the validations are passed, return invisible 'NULL'.
mat1 <- matrix(0, 3, 5)
validMatDims(mat1, 3, 5)
## Check dimnames
mat1 <- matrix(0, 3, 5)
rownames(mat1) <- letters[1:3]
colnames(mat1) <- LETTERS[1:5]
try(validMatDimnames(mat1, row.names = letters[2:4])) ## Error
rownames(mat1) <- c("A", "B", "A")
try(validMatDimnames(mat1, row.names = letters[2:4])) ## Error
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.