splitDataByDate: Data integration for data split

View source: R/splitDataByDate.R

splitDataByDateR Documentation

Data integration for data split

Description

This function splits data by the date of the clinical event and shows the data recorded before or after the clinical event, and calculates the period between the record date and index date based on a self-defined window gap.

Usage

splitDataByDate(
  dxDataFile,
  idColName,
  icdColName,
  dateColName,
  indexDateFile,
  gap = 30
)

Arguments

dxDataFile

A data frame object of clinical diagnostic data with at least 3 columns: ID, ICD, and Date. As for date column, the data format should be YYYY/MM/DD or YYYY-MM-DD.

idColName

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

icdColName

Column name of ICD 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.

indexDateFile

A data frame contained index dates for each patient in an observed period. The column names should be 'ID' and 'indexDate'.

gap

Gap length of the window. Default is 30 (data will be seperated every 30 days).

Details

In most condition, users need to extract data by a specific clinical event (e.g., first diagnosis dates of chronic diseases). Users can define a table of clinical index dates of each patient. The date can be generated by selectCases or first/last admission date by getEligiblePeriod.

Value

A new data.table based on dxDataFile and classified by indexDateFile for each patient

See Also

Other data integration functions: selectCases, getEligiblePeriod, getConditionEra

Examples

# sample file for example

SampleforCertainPatient <- sampleDxFile[grepl("A0|B0|C0|D0",ID),]

head(SampleforCertainPatient)

# Defined index date of patient A0,B0,C0 and D0

indexDateTable <- data.frame(ID = c("A0","B0","C0","D0"),
                             indexDate = c("2023-08-12", "2024-02-12",
                                           "2015-12-05", "2017-01-29"),
                             stringsAsFactors = FALSE)
indexDateTable
# Split data by index date for each patient

splitedData <- splitDataByDate(SampleforCertainPatient, ID, ICD, Date,
                               indexDateFile = indexDateTable,
                               gap = 30)
splitedData[15:19,]

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