reformat_sex function

Reformat a Binary Sex Variable

Reformat a Binary Sex Variable

Reformat a binary sex variable so that it consists entirely of values "Female", "Male", and possibly NA and any values included in except.

reformat_sex(x, except = NULL, factor = TRUE)

Arguments

  • x: A vector.
  • except: Values to exclude when reformatting.
  • factor: Whether the return value should be a factor.

Returns

If factor is TRUE, then reformat_age() returns a factor; otherwise it returns a character vector.

Details

When parsing labels, reformat_sex()

ignores case: "FEMALE" and "fEmAlE"

are equivalent.

White space is removed from the beginning and end of labels.

reformat_sex() does not try to interpreting numeric codes (eg 1, 2).

Examples

reformat_sex(c("F", "female", NA, "MALES")) ## values supplied for 'except' reformat_sex(c("Fem", "Other", "Male", "M"), except = c("Other", "Diverse")) ## return an ordinary character vector reformat_sex(c("F", "female", NA, "MALES"), factor = FALSE)

See Also

age_labels(), reformat_age()