isBinaryMat: Test if a matrix is a binary matrix

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Test if a matrix is a binary matrix (i.e. contains only 0s and 1s, and possibly NA). Adapted from https://stackoverflow.com/a/23276062

Usage

1

Arguments

mat

A matrix. If mat is a data frame it will be converted by data.matrix with a warning.

Value

A logical. TRUE if the matrix is binary, FALSE otherwise

Examples

1
2
3
4
5
6
7
set.seed(123)
x <- matrix(rnorm(100), ncol= 10) # not a binary matrix
y <- matrix(sample(0:1, 100, rep=TRUE), ncol=10) # a binary matrix
z <- y ; z[x>1.5] <- NA #a binary matrix with some NA
isBinaryMat(x) #FALSE
isBinaryMat(y) #TRUE
isBinaryMat(z) #TRUE

pgpmartin/GeneNeighborhood documentation built on Sept. 2, 2021, 6:37 a.m.