groupedDataLongToWide: Data format transformation

View source: R/groupedDataLongToWide.R

groupedDataLongToWideR Documentation

Data format transformation

Description

This function converts the long format of grouped data into a wide format which is fit to other analytical and plotting packages.

Usage

groupedDataLongToWide(
  dxDataFile,
  idColName,
  categoryColName,
  dateColName,
  reDup = TRUE,
  numericOrBinary = B,
  count = 1,
  selectedCaseFile = NULL
)

Arguments

dxDataFile

a groupedDT format data frame generated from four strategies of code classification (using unprocessed ICD codes as input is not recommended).

idColName

Column name of ID column in dxDataFile. Data type of this argumant should be string without quotation marks.

dateColName

Column name of date column in dxDataFile, and the type of date column should be a date format in R or a string format with date information in YYYY/MM/DD or YYYY-MM-DD. Data type of this argumant should be string without quotation marks.

numericOrBinary

The wide format data with or without certain diagnostic categories can be marked as binary True/False or numeric diagnosi time counts. Type N or B (character without quotation mark) to specify one of the method. Default is Binary B.

selectedCaseFile

A data frame with the label of case selected or not. Can be generated by selectCases function or a self-defined data frame (as long as the column names and data type are the same as the output of selectCases function, but not recommended). Default is 'NULL'

Details

The output of this function can be numeric or binary wide format.

Value

A new data.table based on classified dxDataFile dataset and converted into a wide format dataset.

Examples


# Create a grouped data

ELIX <- icdDxToComorbid(dxDataFile = sampleDxFile,
                       idColName = ID,
                       icdColName = ICD,
                       dateColName = Date,
                       icd10usingDate = "2015/10/01",
                       comorbidMethod = elix)

head(ELIX$groupedDT)

# Select case with "Diseases of the urinary system" by level 2 of CCS classification

selectedCaseFile <- selectCases(dxDataFile = sampleDxFile,
                                idColName = ID,
                                icdColName = ICD,
                                dateColName = Date,
                                icdVerColName = NULL,
                                icd10usingDate = "2015/10/01",
                                groupDataType = ccslvl2,
                                caseCondition = "Diseases of the urinary system",
                                caseCount = 1)

# Convert the long format of grouped data into a wide binary format with selected case

groupedDataWide <- groupedDataLongToWide(ELIX$groupedDT,
                                         idColName = ID,
                                         categoryColName = Comorbidity,
                                         dateColName = Date,
                                         selectedCaseFile = selectedCaseFile)
groupedDataWide

DHLab-CGU/emr documentation built on Sept. 2, 2023, 9:16 p.m.