Learn R Programming

icd9 (version 1.3.1)

icd9ComorbidDfToMat: convert matrix of comorbidities into data frame, preserving visitId information

Description

convert matrix of comorbidities into data frame, preserving visitId information

Usage

icd9ComorbidDfToMat(x, visitId = NULL, stringsAsFactors = getOption("stringsAsFactors"))

Arguments

x
data frame, with a visitId column (not necessarily first), and other columns with flags for comorbidities, as such column names are required.
visitId
The name of the column in the data frame which contains the patient or visit identifier. Typically this is the visit identifier, since patients come leave and enter hospital with different ICD-9 codes. It is a character vector of length one. If left empty, or NULL, then an attempt is made to guess which field has the ID for the patient encounter (not a patient ID, although this can of course be specified directly). The guesses proceed until a single match is made. Data frames may be wide with many matching fields, so to avoid false positives, anything but a single match is rejected. If there are no successful guesses, and visitId was not specified, then the first column of the data frame is used.
stringsAsFactors
whether the resulting data frame should have strings, i.e. visitId converted to factor. Default is to follow the current session option.

Examples

Run this code
longdf <- data.frame(visitId = c("a", "b", "b", "c"),
    icd9 = c("441", "4424", "443", "441"))
cmbdf <- icd9ComorbidElix(longdf, return.df = TRUE)
class(cmbdf)
rownames(cmbdf)
mat.out <- icd9ComorbidDfToMat(cmbdf)
stopifnot(is.matrix(mat.out))
mat.out[, 1:4]

Run the code above in your browser using DataLab