Learn R Programming

icd9 (version 1.0)

icd9LongToWide: convert ICD data from long to wide format

Description

This is more complicated than reshape or reshape2::dcast allows. This is a reasonably simple solution using built-in functions.

Usage

icd9LongToWide(x, visitId = NULL, icdId = NULL, prefix = "icd_",
  empty = NA, width = NULL)

Arguments

x

data.frame of long-form data, one column for visitId and one for ICD code

visitId

single character, if NULL will use "visitId" if exists, otherwise the first column

icdId

single character string with name of column containing the ICD codes. If left as NULL, the field is guessed to be the first matching ICD or icd, and a warning is given if multiple columns match.

prefix

character, default "icd_" to prefix new columns

empty

value to fill out empty fields of wide output data, defaults to NA

width,

single integer, if specified, writes out this many columns even if no patients have that many codes. Must be greater than or equal to the maximum number of codes per patient.

See Also

Other ICD-9 convert: convert, convert, icd9DecimalToParts, icd9DecimalToShort, icd9GetMajor, icd9MajMinToCode, icd9MajMinToDecimal, icd9MajMinToParts, icd9MajMinToShort, icd9PartsToDecimal, icd9PartsToShort, icd9ShortToDecimal, icd9ShortToParts; icd9ChaptersToMap; icd9DropLeadingZeroes, icd9DropLeadingZeroesDecimal, icd9DropLeadingZeroesMajor, icd9DropLeadingZeroesShort; icd9WideToLong

Examples

Run this code
# NOT RUN {
longdf <- data.frame(visitId = c("a", "b", "b", "c"),
    icd9 = c("441", "4424", "443", "441"))
  icd9LongToWide(longdf)
  icd9LongToWide(longdf, prefix = "ICD10_", empty = "")
# }

Run the code above in your browser using DataLab