Learn R Programming

icd (version 4.0.6)

wide_vs_long: Set the ICD data structure class of a matrix or data.frame.

Description

These functions take your patient data, and allow you to describe whether it is wide or long. icd never requires you do this, but it may help avoid errors, especially if you have atypical data that might confuse icd's heuristics.

Usage

as.icd_long_data(x, warn = TRUE)

as.icd_wide_data(x, warn = TRUE)

icd_long_data(..., warn = TRUE)

icd_wide_data(x, ..., warn = TRUE)

Arguments

x

Input data is a matrix, data.frame, or a class that inherits one of these base structures, such as a tibble.

warn

Single logical, if TRUE, the default, a warning will be shown if changing class between long and wide types.

...

Data used to construct data frame before setting the appropriate class.

Functions

  • as.icd_long_data: Set class on a matrix or data.frame to icd_long_data. To convert wide to long data, use wide_to_long.

  • as.icd_wide_data: Construct a data.frame, adding the icd_long_data class.

  • icd_long_data: Construct a data.frame, adding the icd_long_data class.

  • icd_wide_data: Construct a data.frame, adding the icd_wide_data class.

Long and Wide Formats

As is common with many data sets, key variables can be concentrated in one column or spread over several. Tools format of clinical and administrative hospital data, we can perform the conversion efficiently and accurately, while keeping some metadata about the codes intact, e.g. whether they are ICD-9 or ICD-10.

Data structure

Long or wide format ICD data are all expected to be in a data frame. The data.frame itself does not carry any ICD classes at the top level, even if it only contains one type of code; whereas its constituent columns may have a class specified, e.g. icd9 or icd10who.

Conversion

To convert between long and wide data, use long_to_wide or wide_to_long. Conversion functions in other packages, such as ddplyr will work, too, but will need some work to account for the typical structure of patient data and diagnostic codes. This is not done with ddplyr, data.table etc because it would add a big dependency burden. This package aims to be agnostic and use base R as much as possible.

See Also

long_to_wide and wide_to_long

Other ICD data types: as.comorbidity_map, set_icd_class

Other ICD data types: as.comorbidity_map, set_icd_class

Other ICD data types: as.comorbidity_map, set_icd_class

Examples

Run this code
# NOT RUN {
(w <- icd_wide_data(
  id = c(1, 2, 3),
  dx01 = c("100", "441", "V20"),
  dx02 = c("E9981", "V10", "44004")
))
wide_to_long(w)
class(uranium_pathology)
class(vermont_dx)
# }

Run the code above in your browser using DataLab