Learn R Programming

drugprepr (version 0.0.4)

isolate_overlaps: Separating overlapping prescription periods

Description

Run this function and then you can either simply discard overlapping intervals or shift them around using an appropriate algorithm.

Usage

isolate_overlaps(data)

Arguments

data

A data frame including variables patid, start_date, stop_date and prodcode

Value

A data frame of patid, prodcode, start_date and stop_date, where intervals are either exactly overlapping or mutually non-overlapping (but not partially overlapping), such that the union of such intervals is equivalent to those originally provided in data

Details

The older implementation used isolateoverlaps from the intervalaverage package and Overlap from the DescTools package. Here we refactor it using functions from tidyverse instead.

See Also

intervalaverage::isolateoverlaps, foverlaps

Examples

Run this code
# NOT RUN {
set.seed(1)
overlapping_data <- data.frame(
  rowid = 1:20,
  patid = 1:2,
  prodcode = 'a',
  start_date = Sys.Date() + c(round(rexp(19, 1/7)), -20),
  qty = rpois(20, 64),
  ndd = sample(seq(.5, 12, by = .5), 20, replace = TRUE),
  stringsAsFactors = FALSE
)
overlapping_data <- transform(overlapping_data,
  stop_date = start_date + qty / ndd
)
isolate_overlaps(overlapping_data)

# }

Run the code above in your browser using DataLab