Learn R Programming

nuggets (version 2.1.2)

is_logicalish: Check if an object is logical or numeric with only 0s and 1s

Description

Check if an object is logical or numeric with only 0s and 1s

Usage

is_logicalish(x)

Value

A logical value indicating whether x is logical or numeric containing only 0s and 1s.

Arguments

x

An R object to check.

Author

Michal Burda

Examples

Run this code
is_logicalish(c(TRUE, FALSE, NA))        # returns TRUE
is_logicalish(c(0, 1, 1, 0, NA))         # returns TRUE
is_logicalish(c(0.0, 1.0, NA))           # returns TRUE
is_logicalish(c(0, 0.5, 1))              # returns FALSE
is_logicalish("TRUE")                    # returns FALSE

Run the code above in your browser using DataLab