wideTimeSeriesLab transforms time-series data into wide format.

wideTimeSeriesLab(
  labData,
  idColName,
  labItemColName,
  windowColName,
  valueColName
)

Arguments

labData

a file or dataframe of laboratory test data with at least 4 columns about patient ID, lab item, test value and test date, respectively.

idColName

the column name that records patient ID in labData.

labItemColName

the column name that records lab item in labData. If lab code is combined by multiple columns, then just simply add + operator between column names, e.g., A + B.

windowColName

the column name that records time window sequence in labData.

Value

A new, wide-formatted data.table.

Details

After setting desired time window, data can further transform into wide format, which is more suitable for analysis. If lab item code is composed by multiple columns, it will automatically combined as one. And there can only be single value column selected in this step. #'

Examples


timeSeriesData <- getTimeSeriesLab(labData = labSample,
                                   idColName = SUBJECT_ID,
                                   labItemColName = ITEMID,
                                   dateColName = CHARTTIME,
                                   valueColName = VALUENUM,
                                   indexDate = first,
                                   gapDate = 360,
                                   completeWindows = TRUE)
imputedData <- imputeTimeSeriesLab(labData = timeSeriesData,
                                   idColName = ID,
                                   labItemColName = ITEMID,
                                   windowColName = Window,
                                   valueColName = Max & Min,
                                   impMethod = mean,
                                   imputeOverallMean=FALSE)
wideTimeSeriesLab(labData = imputedData,
                  idColName = ID,
                  labItemColName = ITEMID,
                  windowColName = Window,
                  valueColName = Max)
#>      ID Window 50811   50861 50904 50906  50912  50931  51222
#>  1:  36      1 12.70   12.00    NA    NA  2.000 161.00 14.600
#>  2:  36      2 12.70   12.00    NA    NA  1.500 143.50 14.500
#>  3:  36      3 12.70   12.00    NA    NA  1.500 143.50 14.500
#>  4:  36      4 12.70   12.00    NA    NA  1.000 126.00 14.400
#>  5: 109      1  7.05   51.00    NA    NA 13.600 151.00 15.700
#>  6: 109      2  7.05   61.75    NA    NA  9.875 177.75 13.625
#>  7: 109      3  7.05   38.00    NA    NA  6.600 150.00 14.400
#>  8: 109      4  7.20   80.00    NA    NA  8.800 256.00 11.300
#>  9: 109      5  6.90   78.00    NA    NA 10.500 154.00 13.100
#> 10: 132      1    NA   59.00    NA    NA  0.600 138.00 15.100
#> 11: 143      1 12.70 1226.00    51   120  2.100 432.00 13.900
#> 12: 145      1 13.00  252.00    32   108 10.800 231.00 12.900