Skip to contents

subsetCohorts() filters an existing cohort table, keeping only the records from cohorts that are specified.

Usage

subsetCohorts(cohort, cohortId, name = tableName(cohort))

Arguments

cohort

A cohort table in a cdm reference.

cohortId

Vector identifying which cohorts to include (cohort_definition_id or cohort_name). Cohorts not included will be removed from the cohort set.

name

Name of the new cohort table created in the cdm object.

Value

Cohort table with only cohorts in cohortId.

Examples

# \donttest{
library(CohortConstructor)

cdm <- mockCohortConstructor(nPerson = 100)

cdm$cohort1 |> subsetCohorts(cohortId = 1)
#> # Source:   table<main.cohort1> [?? x 4]
#> # Database: DuckDB v1.1.2 [unknown@Linux 6.5.0-1025-azure:R 4.4.2/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          4 1998-12-14        2002-02-14     
#>  2                    1          6 2003-04-11        2004-02-23     
#>  3                    1          7 2004-07-31        2004-11-23     
#>  4                    1          7 2004-11-24        2005-11-05     
#>  5                    1          7 2005-11-06        2012-01-12     
#>  6                    1          8 2009-09-13        2012-04-22     
#>  7                    1          9 2011-12-20        2011-12-20     
#>  8                    1          9 2011-12-21        2011-12-29     
#>  9                    1          9 2011-12-30        2012-04-02     
#> 10                    1         12 2000-11-15        2013-03-04     
#> # ℹ more rows
# }