clean_duration {drugprepr}R Documentation

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

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...)

Value

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

Note

Currently the variable name is hard-coded as 'duration', but in principle this could be parametrised for datasets where the column has a different name.

Examples

long_presc <- data.frame(duration = c(100, 300, 400, 800))
clean_duration(long_presc, 6)
clean_duration(long_presc, 12, 'remove')


[Package drugprepr version 0.0.4 Index]