sex_from_chi | R Documentation |
sex_from_chi
takes a CHI number or a vector of CHI numbers
and returns the sex as implied by the CHI number(s). The default return type
is an integer but this can be modified.
sex_from_chi(
chi_number,
male_value = 1L,
female_value = 2L,
as_factor = FALSE,
chi_check = TRUE
)
chi_number |
a CHI number or a vector of CHI numbers with |
male_value , female_value |
optionally supply custom values for Male and Female. Note that that these must be of the same class. |
as_factor |
logical, optionally return as a factor with labels |
chi_check |
logical, optionally skip checking the CHI for validity which will be faster but should only be used if you have previously checked the CHI(s). |
The Community Health Index (CHI) is a register of all patients in NHS Scotland. A CHI number is a unique, ten-digit identifier assigned to each patient on the index.
The ninth digit of a CHI number identifies a patient's sex: odd for men, even for women.
The default behaviour for sex_from_chi
is to first check the CHI number is
valid using check_chi
and then to return 1 for male and 2 for female.
There are options to return custom values e.g. 'M'
and 'F'
or to return
a factor which will have labels 'Male'
and 'Female')
a vector with the same class as male_value
and female_value
,
(integer by default) unless as_factor
is TRUE
in which case a factor will
be returned.
sex_from_chi("0101011237")
sex_from_chi(c("0101011237", "0101336489", NA))
sex_from_chi(
c("0101011237", "0101336489", NA),
male_value = "M",
female_value = "F"
)
sex_from_chi(c("0101011237", "0101336489", NA), as_factor = TRUE)
library(dplyr)
df <- tibble(chi = c("0101011237", "0101336489", NA))
df %>% mutate(chi_sex = sex_from_chi(chi))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.