IsDichotomous: Test If a Variable Contains Only Two Unique Values

View source: R/DescTools.r

IsDichotomousR Documentation

Test If a Variable Contains Only Two Unique Values

Description

Test if a variable contains only two values. The variable does not need to be a numerical value, factors and logicals are supported as well. NAs can be skipped by setting na.rm to TRUE.

Usage

IsDichotomous(x, strict = FALSE, na.rm = FALSE)

Flags(x, na.rm = FALSE)

Arguments

x

a numeric or integer vector, a logical vector or a factor (ordered and unordered)

strict

logical. If set to TRUE, the result will only be TRUE, if x contains exactly 2 levels. If set to FALSE the result will be TRUE for 1 and for 2 levels.

na.rm

logical, indicating whether NA values should be stripped before the computation proceeds. Defaults to FALSE.

Details

IsDichotomous tests a single variable. Flags returns the names of all the dichotomous variables in a list or data.frame.

Value

TRUE if x contains only two unique values, FALSE else

Author(s)

Andri Signorell <andri@signorell.net>

Examples

IsDichotomous(sample(10, 5, replace=TRUE))

AndriSignorell/DescTools documentation built on Nov. 11, 2024, 12:11 p.m.