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

Description Usage Arguments Details Value ICD-9 ICD-10-CM and ICD-10-BE Examples

View source: R/sort.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
sort_icd(x, decreasing = FALSE, short_code = guess_short(x), ...)

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

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

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

## S3 method for class '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.

Details

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

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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 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)]

Example output

The 'icd9' package is deprecated, and should be removed to avoid conflicts with  'icd' . The 'icd' package up to version 2.1 contains tested versions of all the deprecated function names which overlap with those in the old 'icd9' package, e.g., 'icd9ComorbidAhrq' '. It is highly recommended to run the command: 'remove.packages("icd9")'
[1] "C7A" "C79" "C80" "C81" "C7B"
[1] "C7A" "C79" "C80" "C81" "C7B"
[1] 3 6 1 5 2 4
[1] "C7A" "C79" "C80" "C81" "C7B"
[1] "C7A" "C7B" "C79" "C80" "C81"

icd documentation built on July 2, 2020, 4:07 a.m.