close_small_gaps: Close small gaps between successive prescriptions

Description Usage Arguments Value Examples

View source: R/overlap.R

Description

Given a series of prescriptions in data, if one prescription (for the same patient and drug) starts ≤q min_gap days after the previous one finishes, we extend the length of the previous prescription to cover the gap.

Usage

1
close_small_gaps(data, min_gap = 0L)

Arguments

data

A data frame containing columns prodcode, patid, start_date and stop_date

min_gap

Size of largest gaps to close. Default is zero, i.e. do nothing

Value

The input data frame data, possibly with some of the stop_dates changed.

Examples

1
2
3
4
5
6
7
8
gappy_data <- data.frame(
  patid = 1,
  prodcode = 'a',
  start_date = Sys.Date() + (0:6) * 7,
  stop_date = Sys.Date() + (0:6) * 7 + 4
)
close_small_gaps(gappy_data)
close_small_gaps(gappy_data, 7)

belayb/drugprepr documentation built on Dec. 19, 2021, 7:44 a.m.