Skip to contents

sampleCohorts() samples an existing cohort table for a given number of people. All records of these individuals are preserved.

Usage

sampleCohorts(cohort, cohortId = NULL, n, 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.

n

Number of people to be sampled for each included cohort.

name

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

Value

Cohort table with the specified cohorts sampled.

Examples

# \donttest{
library(CohortConstructor)

cdm <- mockCohortConstructor(nPerson = 100)

cdm$cohort2 |> sampleCohorts(cohortId = 1, n = 10)
#> # Source:   table<main.cohort2> [?? 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         13 2014-06-24        2014-06-29     
#>  2                    1         13 2014-06-30        2014-08-07     
#>  3                    1         35 2018-01-07        2018-02-19     
#>  4                    1         35 2018-02-20        2018-03-22     
#>  5                    1         38 1990-05-01        1994-07-14     
#>  6                    1         45 1998-02-22        2000-05-25     
#>  7                    1         45 2000-05-26        2007-09-06     
#>  8                    1         53 2003-05-29        2006-06-20     
#>  9                    1         60 1974-02-12        1979-10-10     
#> 10                    1         70 1965-04-30        1965-05-20     
#> # ℹ more rows
# }