
Require cohort entries last for a certain number of days
Source:R/requireDuration.R
requireDuration.Rd
requireDuration()
filters cohort records, keeping only those which last
for the specified amount of days
Usage
requireDuration(
cohort,
daysInCohort,
cohortId = NULL,
name = tableName(cohort)
)
Arguments
- cohort
A cohort table in a cdm reference.
- daysInCohort
Number of days cohort entries must last. Can be a vector of length two if a range, or a vector of length one if a specific number of days. Note, cohort entry and exit on the same day counts as one day in the cohort. So if, for example, you wish to require individuals are in the cohort for at least one night then set daysInCohort to c(2, Inf). Meanwhile, if set to c(30, 90) then only cohort entries that are 30 days or more longer and shorter or equal to 90 days will be kept.
- cohortId
Vector identifying which cohorts to modify (cohort_definition_id or cohort_name). If NULL, all cohorts will be used; otherwise, only the specified cohorts will be modified, and the rest will remain unchanged.
- name
Name of the new cohort table created in the cdm object.
Value
The cohort table with any cohort entries that last less or more than the required duration dropped
Examples
# \donttest{
library(CohortConstructor)
cdm <- mockCohortConstructor()
cdm$cohort1 |>
requireDuration(daysInCohort = c(2, Inf))
#> # A tibble: 61 × 4
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> * <int> <int> <date> <date>
#> 1 1 2 1994-03-16 1996-04-10
#> 2 1 3 1980-01-03 1980-05-22
#> 3 1 4 1999-04-10 1999-06-21
#> 4 1 5 1996-07-30 1998-10-20
#> 5 1 6 1992-11-19 1993-10-01
#> 6 1 7 2005-12-14 2006-03-18
#> 7 1 9 2013-02-20 2019-03-19
#> 8 1 10 2008-12-31 2014-04-28
#> 9 1 12 1995-05-29 2004-04-05
#> 10 1 14 2007-09-09 2008-02-25
#> # ℹ 51 more rows
# }