shrink_interval: Cleaning the time periods with overlapping gaps or small gaps

View source: R/clean.R

shrink_intervalR Documentation

Cleaning the time periods with overlapping gaps or small gaps

Description

Merge those overlapping records or records with a small interval. For instance, the two prescription records with an small gap can be considered as a same one. Or two successive hospitalizations can be merged as one.

Usage

shrink_interval(data, st, ed, gap = 1)

Arguments

data

the dataset with starting point and ending points, which is in yyyymmdd format

st

the column name for starting date

ed

the column name for ending date

gap

the gap between two prescription records which you would like to merge. For instance, n = 7 when two Rx records with interval less than 7 days may be consider as the same prescription.

Value

A data table will be generate with merged interval.

Examples

data <- data.table(id=rep(1,2),
        date_st=lubridate::ymd(c("2021-1-1","2021-1-4")),
        date_end=lubridate::ymd(c("2021-1-5","2021-1-6")))
shrink_interval(data,"date_st","date_end",gap=2)

Cainefm/MND documentation built on Aug. 13, 2022, 3:33 p.m.