
Trim cohort dates to be within a certain interval of days
Source:R/requireDuration.R
trimDuration.Rd
trimDuration()
resets the cohort start and end date, keeping only those
which include the specified amount of days
Usage
trimDuration(cohort, daysInCohort, cohortId = NULL, name = tableName(cohort))
Arguments
- cohort
A cohort table in a cdm reference.
- daysInCohort
Number of days cohort relative to current cohort start dates. Cohort entries will be trimmed to these dates. Note, cohort entry and exit on the same day counts as one day in the cohort.Set lower bound to 1 if keeping cohort start to the same as current cohort start.
- 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: 64 × 4
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> * <int> <int> <date> <date>
#> 1 1 1 2006-10-20 2014-01-17
#> 2 1 4 2007-01-01 2011-05-19
#> 3 1 5 2009-11-28 2009-12-12
#> 4 1 6 2002-09-09 2002-09-19
#> 5 1 7 1987-07-19 1989-08-26
#> 6 1 8 2003-02-07 2003-02-17
#> 7 1 9 2013-06-28 2015-03-28
#> 8 1 10 1990-11-10 1999-10-28
#> 9 1 11 1968-03-08 1970-02-28
#> 10 1 12 1998-09-16 2001-05-01
#> # ℹ 54 more rows
# }