icd_expand: Expand list of ICD codes to include all possible subcodes

Description Usage Arguments Value See Also Examples

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

1
2
3
4
5
6
7
8
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 icd_parse. This must be one of "strict" (str contains a ICD code with no extraneous characters), bounded (str contains an ICD code with a word boundary on both sides) or weak (ICD codes are extracted even if they are contained within a word, e.g. "E10Diabetes" would return "E10"). Default: strict.

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: FALSE, stop on error.

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

1
2
3
4
5
6
7
8
9
# 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")

edonnachie/ICD documentation built on Dec. 10, 2019, 11:35 a.m.