View source: R/reduce.matrix.R
| reduce.matrix | R Documentation | 
Reduce the number of rows/columns in a matrix to optimise overlap
reduce.matrix(matrix, distance = "gower", by.row = TRUE, verbose = FALSE)
| matrix | A matrix | 
| distance | which distance to consider (passed to  | 
| by.row | Whether to do it by rows ( | 
| verbose | Whether to do be verbose ( | 
Thomas Guillerme
set.seed(1)
## A 10*5 matrix
na_matrix <- matrix(rnorm(50), 10, 5)
## Making sure some rows don't overlap
na_matrix[1, 1:2] <- NA
na_matrix[2, 3:5] <- NA
## Adding 50% NAs
na_matrix[sample(1:50, 25)] <- NA
## Illustrating the gappy matrix
image(t(na_matrix), col = "black")
## Reducing the matrix by row
(reduction <- reduce.matrix(na_matrix))
## Illustrating the overlapping matrix
image(t(na_matrix[-as.numeric(reduction$rows.to.remove), ]), col = "black")
## Reducing the matrix by columns (and being verbose)
reduce.matrix(na_matrix, by.row = FALSE, verbose = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.