Learn R Programming

icd (version 2.2)

icd_sort: Sort short-form ICD-9 codes

Description

Sorts lists of numeric only, 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.

Usage

icd_sort(x, ...)

# S3 method for default icd_sort(x, short_code = icd_guess_short(x), ...)

# S3 method for icd10 icd_sort(x, short_code = NULL, ...)

# S3 method for icd9 icd_sort(x, short_code = icd_guess_short(x), ...)

Arguments

x

vector of ICD codes to sort

...

arguments passed on to other functions

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.

Value

sorted vector of ICD-9 codes. Numeric, then E codes, then V codes.

Methods (by class)

  • default: Guess whether ICD-9 or ICD-10 (or possibly sub-type in the future) then sort based on that type. ICD-10 codes, note that setting short is unnecessary and ignored.

  • icd10: Sort ICD-10 codes, note that setting short is unnecessary and ignored.

  • icd9: sort ICD-9 codes respecting numeric, then 'V', then 'E' codes, and accounting for leading zeroes. Will return a factor if a factor is given.

Details

Implementation used fast built-in sort, then shuffles the E codes to the end.