Remove values from Matrix based on threshold

Share:

Description

Returns matrix with values above or below the threshold are replaced. Can be used for converting to a binary matrix or for thresholding an adjacency matrix.

Usage

1
matrix_threshold(matrix, threshold=NULL, minval=0, maxval=NULL, abs=TRUE, rmna=FALSE,...)

Arguments

matrix

matrix

threshold

Integer

minval

Integer. Replaces values below threshold.

maxval

Integer. Replaces values above or equal to threshold.

abs

Logical. If TRUE the absolute value will be considered.

rmna

Logical. If TRUE NA's will be replaced with minval.

...

Other parameters.

Details

If rm.na is TRUE and minval is NULL, then NA's will be replaced with 0.

Value

max_threshold returns an matrix with values removed according to parameters.

Author(s)

Shannon M. Bell

Examples

1
2
3
4
5
 #using USArrest dataset
 arrestCor<-cor(t(USArrests))
 arrestCor.7<-matrix_threshold(arrestCor, threshold=0.7, minval=0, abs=TRUE, rm.na=FALSE)
 arrestCor[10:15,1:5]
 arrestCor.7[10:15,1:5]