Description Usage Arguments Details Value Note Examples
Given a prescription length limit, truncate any prescriptions that appear to be longer than this, or mark them as missing.
1 | clean_duration(data, max_months = Inf, method = c("truncate", "remove"))
|
data |
A data frame containing a column called |
max_months |
The maximum plausible prescription length in months |
method |
Either 'truncate' or 'remove'. See 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...)
A data frame of the same structure as the input, possibly with some elements of the duration column changed
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.
1 2 3 | long_presc <- data.frame(duration = c(100, 300, 400, 800))
clean_duration(long_presc, 6)
clean_duration(long_presc, 12, 'remove')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.