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.0.0 [unknown@Linux 6.5.0-1025-azure:R 4.4.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          1 2001-02-15        2001-10-28     
#>  2                    1          1 2001-10-29        2003-03-15     
#>  3                    1          1 2003-03-16        2005-02-08     
#>  4                    1          2 1999-11-11        2002-04-09     
#>  5                    1          6 2011-03-07        2014-01-24     
#>  6                    1          7 2014-03-08        2014-03-19     
#>  7                    1         10 2019-12-04        2019-12-14     
#>  8                    1         13 2014-06-24        2014-06-29     
#>  9                    1         13 2014-06-30        2014-08-07     
#> 10                    1         14 1986-11-29        1987-12-14     
#> # ℹ more rows
# }