dcast
in reshape2
that
it needs writing again specifically for ICD codes. This function packages
the core reshape
function. Empty strings and NA values will be
dropped, and everything else kept. No validation of the ICD codes is done.
icd9WideToLong(x, visitId = NULL, icdLabels = NULL, icdName = "icdCode", icdRegex = c("icd", "diag", "dx_", "dx"), verbose = FALSE)
data.frame
in wide format, i.e. one row per patient, and
multiple columns containing ICD codes, empty strings or NA.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.c("icd", "diag", "dx_", "dx")
FALSE
in most functions.icd.name
containing all the non-NA and non-empty codes
found in the wide input data.
icd9ChaptersToMap
,
icd9DropLeadingZeroes
,
icd9LongToWide
,
icd9PartsToShort
widedf <- data.frame(visitId = c("a", "b", "c"),
icd9_01 = c("441", "4424", "441"),
icd9_02 = c(NA, "443", NA))
icd9WideToLong(widedf)
Run the code above in your browser using DataLab