icd9ComorbidMatToDf: convert matrix of comorbidities into data frame, preserving...

Description Usage Arguments Examples

View source: R/convert.R

Description

convert matrix of comorbidities into data frame, preserving visitId information

Usage

1
2
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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]

Example output

The icd9 package is now deprecated. The new 'icd' package is on CRAN and has ICD-10 support and bug-fixes. All the functions available in 'icd9' have been preserved in 'icd', but a simpler set of function names is also available.

To install it, use:
install.packages("icd")
# or for the development version:
devtools::install_github("jackwasey/icd")

Then:
remove.packages("icd9")

[1] "matrix"
[1] "logical"
[1] "a" "b" "c"
  visitId   CHF Arrhythmia Valvular
a       a FALSE      FALSE    FALSE
b       b FALSE      FALSE    FALSE
c       c FALSE      FALSE    FALSE

icd9 documentation built on May 30, 2017, 2:25 a.m.