Learn R Programming

drugprepr (version 0.0.4)

clean_duration: Clean implausibly-long prescription durations

Description

Given a prescription length limit, truncate any prescriptions that appear to be longer than this, or mark them as missing.

Usage

clean_duration(data, max_months = Inf, method = c("truncate", "remove"))

Arguments

data

A data frame containing a column called duration

max_months

The maximum plausible prescription length in months

method

Either 'truncate' or 'remove'. See details

Value

A data frame of the same structure as the input, possibly with some elements of the duration column changed

Details

The method 'truncate' causes any duration longer than max_months to be replaced with the value of max_months (albeit converted to days). The method 'remove' causes such durations to be replaced with NA. There is no explicit 'ignore' method, but if you want to 'do nothing', simply set max_months to an arbitrarily high number. By default, the maximum is infinite, so nothing should happen. (Of course, you could also just not run the function...)

Examples

Run this code
# NOT RUN {
long_presc <- data.frame(duration = c(100, 300, 400, 800))
clean_duration(long_presc, 6)
clean_duration(long_presc, 12, 'remove')

# }

Run the code above in your browser using DataLab