Learn R Programming

surveytable (version 0.9.7)

var_case: Convert factor to logical

Description

Convert factor to logical

Usage

var_case(newvr, vr, cases, retain_na = TRUE)

Value

Survey object

Arguments

newvr

name of the new logical variable to be created

vr

factor variable

cases

one or more levels of vr that are converted to TRUE. All other levels are converted to FALSE.

retain_na

for the observations where vr is NA, should newvr be NA as well?

See Also

Other variables: var_all(), var_any(), var_collapse(), var_copy(), var_cross(), var_cut(), var_not()

Examples

Run this code
set_survey(namcs2019sv)

var_case("Preventive care visits", "MAJOR", "Preventive care")
tab("Preventive care visits")

var_case("Surgery-related visits"
, "MAJOR"
, c("Pre-surgery", "Post-surgery"))
tab("Surgery-related visits")

var_case("Non-primary"
, "SPECCAT.bad"
, c("Surgical care specialty", "Medical care specialty"))
tab("Non-primary")
tab("Non-primary", drop_na = TRUE)

Run the code above in your browser using DataLab