reduce.matrix: Reduce a matrix

View source: R/reduce.matrix.R

reduce.matrixR Documentation

Reduce a matrix

Description

Reduce the number of rows/columns in a matrix to optimise overlap

Usage

reduce.matrix(matrix, distance = "gower", by.row = TRUE, verbose = FALSE)

Arguments

matrix

A matrix

distance

which distance to consider (passed to vegdist, default = "gower")

by.row

Whether to do it by rows (TRUE - default), or by columns (FALSE)

verbose

Whether to do be verbose (TRUE) or not (FALSE - default)

Author(s)

Thomas Guillerme

Examples

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)


TGuillerme/dispRity documentation built on Dec. 21, 2024, 4:05 a.m.