Learn R Programming

icd (version 4.0.6)

sort_icd: Sort or order ICD-9 or ICD-10 codes according to published sequence

Description

The default method will guess whether ICD-9 or ICD-10 then sort based on that type. For ICD-10 codes, note that setting short is unnecessary and ignored. All codes should consistently use the decimal divider.

Usage

sort_icd(x, decreasing = FALSE, short_code = guess_short(x), ...)

# S3 method for icd10 sort(x, decreasing = FALSE, ...)

# S3 method for icd10cm sort(x, decreasing = FALSE, ...)

# S3 method for icd10be sort(x, decreasing = FALSE, ...)

# S3 method for icd9 sort(x, decreasing = FALSE, short_code = guess_short(x), ...)

order.icd9(x, na.last = TRUE)

order.icd10cm(x)

order.icd10be(x)

Arguments

x

vector of ICD codes to sort or order

decreasing

Logical See sort.

short_code

single logical value which determines whether the ICD-9 code provided is in short (TRUE) or decimal (FALSE) form. Where reasonable, this is guessed from the input data.

...

arguments passed on to other functions

na.last

Logical, analogous to order, so NA drops NA. FALSE is not currently supported.

Value

For sort, a sorted vector of ICD-9 codes. Numeric, then E codes, then V codes. For order, an integer vector is returned with the order of each code.

ICD-9

Sorts lists of numeric, V or E codes. Note that a simple numeric sort does not work for ICD-9 codes, since 162 > 1620, and also ‘V’ codes precede ‘E’ codes. Numeric codes are first, then ‘V’, then ‘E’. A factor is returned if a factor is given.

ICD-10-CM and ICD-10-BE

There are some codes which are sequenced out of lexicographic order, e.g., C7A and C7B are between C80 and C81; D3A is between D48 and D49.

Details

Note that sort is an S3 generic, whereas order is not. Thus we export order.icd10cm, but not sort.icd10cm, etc..

Examples

Run this code
# NOT RUN {
# order ICD-10-CM is not lexicographic:
codes <- as.icd10cm(c("C7A", "C79", "C80", "C81", "C7B"))
# as the class is set, use S3 dispatch to get the right answer
sort(codes)
# or call directly, but recall S3 dispatch will only work once 'icd' is
# attached using:
library(icd)
icd:::sort.icd10cm(c("C7A", "C79", "C80", "C81", "C7B"))
stopifnot(!identical(
  order.icd10cm(as.character(codes)),
  order(codes)
))
icd::order.icd9(c("V20", NA, "100", NA, "E998", "101"))
codes[order.icd10cm(codes)]
# Note that base::order does NOT do S3 dispatch, so the following does not work:
codes[order(codes)]
# }

Run the code above in your browser using DataLab