| isolate_overlaps {drugprepr} | R Documentation |
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 |
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.
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
Note
This function currently doesn't use any keys except patid and
prodcode. It may be desirable to add a row ID, for matching each
partial interval back to the original interval from which it was derived.
This may be relevant to models using weighted dosages.
See Also
intervalaverage::isolateoverlaps,
foverlaps
Examples
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)