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.1 [unknown@Linux 6.11.0-1015-azure:R 4.5.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 1 30 1988-06-16 1995-05-24
#> 2 1 30 1998-03-06 1999-12-26
#> 3 1 31 2019-03-25 2019-04-20
#> 4 1 31 2019-04-25 2019-06-11
#> 5 1 31 2019-06-13 2019-07-07
#> 6 1 38 1985-12-28 1993-08-14
#> 7 1 38 1993-08-15 1997-02-10
#> 8 1 40 1990-12-13 1992-01-18
#> 9 1 43 1996-09-18 1996-09-19
#> 10 1 43 1996-10-05 1996-11-09
#> # ℹ more rows
# }