Learn R Programming

ddgraph (version 1.16.0)

is.binary: Check if data structure has binary data in it

Description

Check if a vector, data frame or matrix contains only binary (0,1) values.

Usage

is.binary(x)

Arguments

x
the input vector, data.frame or matrix

Value

Examples

Run this code
is.binary(0)
is.binary(c(1, 0, 0, 1, 0))
is.binary(matrix(c(1,0), nrow=2, ncol=2))
is.binary(data.frame("a"=c(1,0), "b"=c(0,1)))

# returns FALSE if not binary
is.binary(c(1, 2, 3))

Run the code above in your browser using DataLab