convert_to_logical: Convert variables to logical

View source: R/convert_to_logical.R

convert_to_logicalR Documentation

Convert variables to logical

Description

This is particularly useful for binary variables that have been encoded with e.g. Yes and No as options. Variable labels are retained, which may or may not make sense, depending on the variable

Usage

convert_to_logical(
  data,
  vars,
  true = "Yes",
  replace = TRUE,
  append = "_logical"
)

Arguments

data

dataframe

vars

character string of variables to convert

true

value which should become TRUE

replace

Replace the indicated variables

append

text to append to new variables (when replace = TRUE)

Value

data with modified variables, potentially with additional variables (if replace = TRUE)

Examples

data(mtcars)
convert_to_logical(mtcars, "am", 1)
convert_to_logical(mtcars, c("am", "vs"), 1)
convert_to_logical(mtcars, c("am", "vs"), 1, FALSE)
convert_to_logical(mtcars, c("am", "vs"), 1, FALSE, "_lgl")

aghaynes/redcaptools documentation built on April 5, 2025, 9:28 a.m.