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 1.4.0 [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 15 1988-05-09 2003-06-21
#> 2 1 31 2019-03-25 2019-04-20
#> 3 1 31 2019-04-25 2019-06-11
#> 4 1 31 2019-06-13 2019-07-07
#> 5 1 34 2017-07-18 2017-12-07
#> 6 1 34 2017-12-08 2018-02-26
#> 7 1 46 1980-02-04 1980-12-16
#> 8 1 46 1985-04-02 1988-11-03
#> 9 1 47 1987-10-01 1990-01-31
#> 10 1 54 1981-02-26 1982-04-20
#> # ℹ more rows
# }