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

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'

Value

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

Details

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

Examples


# Create a grouped data

ELIX <- icdDxToComorbid(dxDataFile = sampleDxFile,
                       idColName = ID,
                       icdColName = ICD,
                       dateColName = Date,
                       icd10usingDate = "2015/10/01",
                       comorbidMethod = elix)
#> Wrong ICD format: total 9 ICD codes (the number of occurrences is in brackets)
#> c("A0.11 (20)", "E114 (8)", "Z9.90 (6)", "F42 (6)", "001 (5)", "75.52 (4)", "755.2 (3)", "123.45 (3)", "7552 (2)")
#> 	
#> Wrong ICD version: total 7 ICD codes (the number of occurrences is in brackets)
#> c("V27.0 (18)", "A01.05 (8)", "42761 (7)", "V24.1 (6)", "A0105 (5)", "E03.0 (4)", "650 (4)")
#> 	
#> Warning: The ICD mentioned above matches to "NA" due to the format or other issues.
#> Warning: "Wrong ICD format" means the ICD has wrong format
#> Warning: "Wrong ICD version" means the ICD classify to wrong ICD version (cause the "icd10usingDate" or other issues)

head(ELIX$groupedDT)
#>    Short  ID  ICD       Date Comorbidity
#> 1:  Z992  A2 Z992 2020-05-22    RENLFAIL
#> 2:  Z992  A5 Z992 2020-01-24    RENLFAIL
#> 3:  Z992  A8 Z992 2015-10-27    RENLFAIL
#> 4:  Z992 A13 Z992 2020-04-26    RENLFAIL
#> 5:  Z992 A13 Z992 2025-02-02    RENLFAIL
#> 6:  Z992 A15 Z992 2023-05-12    RENLFAIL

# 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)
#> Wrong ICD format: total 9 ICD codes (the number of occurrences is in brackets)
#> c("A0.11 (20)", "E114 (8)", "Z9.90 (6)", "F42 (6)", "001 (5)", "75.52 (4)", "755.2 (3)", "123.45 (3)", "7552 (2)")
#> 	
#> Wrong ICD version: total 7 ICD codes (the number of occurrences is in brackets)
#> c("V27.0 (18)", "A01.05 (8)", "42761 (7)", "V24.1 (6)", "A0105 (5)", "E03.0 (4)", "650 (4)")
#> 	
#> Warning: The ICD mentioned above matches to "NA" due to the format or other issues.
#> Warning: "Wrong ICD format" means the ICD has wrong format
#> Warning: "Wrong ICD version" means the ICD classify to wrong ICD version (cause the "icd10usingDate" or other issues)

# 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
#>      ID  ARTH CHRNLUNG  DMCX  DRUG HRENWORF HTNPREG LIVER LYMPH NEURO OBESE
#>  1:  A0 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#>  2:  A1 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#>  3: A10 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#>  4: A11 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#>  5: A12 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#>  6: A13 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#>  7: A14 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#>  8: A15 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#>  9: A16 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 10: A17 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 11: A18 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 12:  A2 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 13:  A3 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 14:  A4 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 15:  A5 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 16:  A6 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 17:  A7 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 18:  A8 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 19:  A9 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 20:  B0 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 21:  B1 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 22:  B2 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 23:  B3 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 24:  B4 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 25:  C0 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 26:  C1 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 27:  C2 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 28:  C3 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 29:  C4 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 30:  D0  TRUE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 31:  D1  TRUE    FALSE FALSE FALSE     TRUE   FALSE  TRUE FALSE FALSE FALSE
#> 32:  D2 FALSE    FALSE FALSE  TRUE    FALSE   FALSE FALSE  TRUE  TRUE FALSE
#> 33:  D3 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE FALSE  TRUE  TRUE
#> 34:  D4 FALSE    FALSE  TRUE FALSE    FALSE    TRUE FALSE  TRUE FALSE FALSE
#> 35:  D5  TRUE     TRUE FALSE FALSE    FALSE   FALSE FALSE  TRUE FALSE FALSE
#> 36:  D6  TRUE    FALSE  TRUE  TRUE    FALSE   FALSE FALSE FALSE  TRUE FALSE
#> 37:  D7  TRUE    FALSE FALSE  TRUE    FALSE   FALSE FALSE FALSE FALSE FALSE
#> 38:  D8 FALSE    FALSE FALSE FALSE    FALSE   FALSE FALSE  TRUE FALSE FALSE
#>      ID  ARTH CHRNLUNG  DMCX  DRUG HRENWORF HTNPREG LIVER LYMPH NEURO OBESE
#>      PARA PERIVASC PSYCH RENLFAIL TUMOR ULCER VALVE WGHTLOSS selectedCase
#>  1: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#>  2: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#>  3: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#>  4: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#>  5: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#>  6: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#>  7: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#>  8: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#>  9: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 10: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 11: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 12: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 13: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 14: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 15: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 16: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 17: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 18: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 19: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 20: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 21: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 22: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 23: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 24: FALSE    FALSE FALSE     TRUE FALSE FALSE FALSE    FALSE     Selected
#> 25: FALSE    FALSE FALSE    FALSE  TRUE FALSE FALSE    FALSE non-Selected
#> 26: FALSE    FALSE FALSE    FALSE  TRUE FALSE FALSE    FALSE non-Selected
#> 27: FALSE    FALSE FALSE    FALSE  TRUE FALSE FALSE    FALSE non-Selected
#> 28: FALSE    FALSE FALSE    FALSE  TRUE FALSE FALSE    FALSE non-Selected
#> 29: FALSE    FALSE FALSE    FALSE  TRUE FALSE FALSE    FALSE non-Selected
#> 30: FALSE    FALSE  TRUE    FALSE FALSE  TRUE FALSE    FALSE non-Selected
#> 31: FALSE    FALSE FALSE    FALSE FALSE FALSE FALSE     TRUE non-Selected
#> 32: FALSE    FALSE FALSE    FALSE FALSE FALSE  TRUE    FALSE non-Selected
#> 33: FALSE     TRUE  TRUE    FALSE FALSE FALSE FALSE    FALSE non-Selected
#> 34:  TRUE    FALSE FALSE    FALSE FALSE FALSE FALSE    FALSE non-Selected
#> 35: FALSE    FALSE FALSE    FALSE FALSE FALSE  TRUE    FALSE non-Selected
#> 36: FALSE    FALSE FALSE    FALSE FALSE FALSE FALSE    FALSE non-Selected
#> 37: FALSE    FALSE  TRUE    FALSE  TRUE FALSE FALSE    FALSE non-Selected
#> 38:  TRUE     TRUE  TRUE    FALSE FALSE FALSE FALSE    FALSE non-Selected
#>      PARA PERIVASC PSYCH RENLFAIL TUMOR ULCER VALVE WGHTLOSS selectedCase