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<cohort2> [?? x 4]
#> # Database: DuckDB v1.3.2 [unknown@Linux 6.11.0-1018-azure:R 4.5.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 1 16 2016-10-31 2016-11-22
#> 2 1 17 1979-09-09 1983-01-12
#> 3 1 30 1988-06-16 1995-05-24
#> 4 1 30 1998-03-06 1999-12-26
#> 5 1 34 2017-07-18 2017-12-07
#> 6 1 34 2017-12-08 2018-02-26
#> 7 1 40 1990-12-13 1992-01-18
#> 8 1 53 2013-05-03 2013-06-06
#> 9 1 53 2013-07-14 2013-07-30
#> 10 1 57 1996-10-25 1999-06-28
#> # ℹ more rows
# }