long_to_wide {icdcomorbid}R Documentation

Reshape Long Format Data to Wide Format

Description

This is a preprocessing step to transform a dataframe from long to wide format to use with icd_to_comorbid function.

Usage

long_to_wide(df, idx, icd_cols, batch_size = 1000)

Arguments

df

The dataframe to be converted.

idx

The name of the column containing the unique identifier (ID).

icd_cols

A character vector specifying the names of the columns containing ICD codes.

batch_size

An optional integer specifying the number of rows to process per batch. Default is 1000.

Value

A dataframe in wide format where each row represents a unique identifier (ID), and each column contains a variable associated with that ID.

References

ICD: Python library for working with International Classification of Diseases (ICD) codes. Available online: https://github.com/mark-hoffmann/icd

Examples

df <- data.frame( ID = c(1, 1, 2, 2, 3, 3, 3),
                 icd_1 = c("I10.2", "E03.9", "E11.9", "N18.9", "A04.7", NA, NA),
                 icd_2 = c("I11.9", "E78.5", "E78.2", "E14.9","A04.7", "E11.9", NA))
long_to_wide(df, "ID", c("icd_1", "icd_2"), batch_size = 1000)

[Package icdcomorbid version 1.0.0 Index]