makeLogical: Logical variable check

Description Usage Arguments Details Value Examples

View source: R/utilities-data-validation.R

Description

Utility function to verify that a variable is dichotomous.

Usage

1

Arguments

x

Vector containing two unique types of values.

Details

This function effectively allows the user to ask for any variable containing at most two unique values to treat the variable as logical. If the variable contains numeric values, the highest value is recoded 1 and the the lower value is recoded 0. If the variable is categorical and contains only two unique values, the least frequently observed is recoded 1.

Value

Logical form of x coded 0-1.

Examples

1
2
3
makeLogical(sample(c('cat', 'dog'), size=8, replace=TRUE))
makeLogical(sample(c(0, 1), size=8, replace=TRUE))
makeLogical(sample(c(-6.87, 3.23), size=8, replace=TRUE))

IQSS/PSI-Library documentation built on Feb. 15, 2020, 9:03 p.m.