Skip to contents

Turns a numeric or character sex variable into a two-level factor with the levels `"male"` and `"female"`. Doing this once near the top of an analysis removes the 0/1 versus 1/2 ambiguity from every later call.

Usage

eiod_as_sex_factor(x, male, female, labels = c("male", "female"))

Arguments

x

A numeric or character vector of sex codes.

male, female

The value of `x` that means male and female respectively. Both are required: see the discussion in [eiod_age_sex_group()] for why this is not inferred.

labels

The two level labels to use, male first.

Value

A factor with two levels, `NA` preserved.

Examples

eiod_as_sex_factor(c(1, 2, 2, 1), male = 1, female = 2)
#> [1] male   female female male  
#> Levels: male female
eiod_as_sex_factor(c(0, 1, 1), male = 1, female = 0)
#> [1] female male   male  
#> Levels: male female
eiod_as_sex_factor(c("M", "F"), male = "M", female = "F")
#> [1] male   female
#> Levels: male female