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.
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-1020-azure:R 4.4.2/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 1 14 1998-11-10 1999-03-09
#> 2 1 14 1999-03-10 2001-06-02
#> 3 1 14 2001-06-03 2001-12-04
#> 4 1 15 2018-03-20 2018-04-01
#> 5 1 30 2007-01-25 2007-08-27
#> 6 1 30 2007-08-28 2008-07-23
#> 7 1 31 2012-09-03 2013-02-18
#> 8 1 31 2013-02-19 2013-03-28
#> 9 1 31 2013-03-29 2014-04-29
#> 10 1 39 2000-03-07 2009-03-17
#> # ℹ more rows
# }