Learn R Programming

icd9 (version 1.3.1)

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

Description

convert matrix of comorbidities into data frame, preserving visitId information

Usage

icd9ComorbidMatToDf(x, visitId = "visitId", stringsAsFactors = getOption("stringsAsFactors"))

Arguments

x
Matrix of comorbidities, with row and columns names defined
visitId
Single character string with name for new column in output data frame. Everywhere else, visitId describes the input data, but here it is for output data.
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"))
mat <- icd9ComorbidElix(longdf)
class(mat)
typeof(mat)
rownames(mat)
df.out <- icd9ComorbidMatToDf(mat)
stopifnot(is.data.frame(df.out))
# output data frame has a factor for the visitId column
stopifnot(identical(rownames(mat), as.character(df.out$visitId)))
df.out[, 1:4]

Run the code above in your browser using DataLab