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, n, cohortId = NULL, name = tableName(cohort))

Arguments

cohort

A cohort table in a cdm reference.

n

Number of people to be sampled for each included cohort.

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

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.1.3 [unknown@Linux 6.8.0-1017-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          8 2009-09-13        2012-04-22     
#>  3                    1         31 2012-09-03        2013-02-18     
#>  4                    1         31 2013-02-19        2013-03-28     
#>  5                    1         31 2013-03-29        2014-04-29     
#>  6                    1         35 2007-01-05        2007-05-12     
#>  7                    1         35 2007-05-13        2010-07-22     
#>  8                    1         37 1999-02-05        2002-12-01     
#>  9                    1         43 1987-05-07        1987-05-08     
#> 10                    1         43 1987-05-09        1995-03-03     
#> # ℹ more rows
# }