icd_expand {ICD10gm} | R Documentation |
Expand list of ICD codes to include all possible subcodes
Description
The function icd_expand
takes a data.frame containing ICD codes
and optional metadata as input. It returns a data.frame containing
all ICD codes at or below the specified level of the hierarchy
(e.g. the specification "E11" is expanded to include all three,
four and five-digit codes beginning with E11).
Usage
icd_expand(
icd_in,
year,
col_icd = "ICD",
col_meta = NULL,
type = "strict",
ignore_icd_errors = FALSE
)
Arguments
icd_in |
Data frame defining ICD codes of interest |
year |
ICD 10 version |
col_icd |
Column of icd_in containing ICD codes (Default: ICD) |
col_meta |
(Optional) Columns containing meta information to retain (e.g. Grouper, age or other criteria for later use). If left NULL, only col_icd is retained. |
type |
A character string determining how strictly matching should be performed, passed to |
ignore_icd_errors |
logical. Whether to ignore incorrectly specified input (potentially leading to incomplete output) or stop if any ICD specification does not correspond to a valid ICD code. Default: |
Value
data.frame with columns YEAR, ICD_CODE, ICD_COMPRESSED, ICD_LABEL and, if specified, columns specified by col_meta
See Also
icd_history()
to historize the output
Examples
# Incomplete or non-terminal codes expand to the right.
# This is useful to specified code blocks in a compact manner
icd_meta <- data.frame(ICD = "R1")
icd_expand(icd_meta, year = 2019)
# Optional metadata columns can be carried
# through with the specification
icd_meta <- data.frame(ICD = "M54", icd_label = "Back pain")
icd_expand(icd_meta, year = 2019, col_meta = "icd_label")