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.2 [unknown@Linux 6.5.0-1025-azure:R 4.4.2/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 1 16 2005-12-28 2008-06-11
#> 2 1 27 1992-04-16 1993-09-30
#> 3 1 27 1993-10-01 2003-08-01
#> 4 1 37 1999-02-05 2002-12-01
#> 5 1 43 1987-05-07 1987-05-08
#> 6 1 43 1987-05-09 1995-03-03
#> 7 1 54 2014-11-14 2016-06-22
#> 8 1 62 2007-12-22 2008-12-08
#> 9 1 64 2018-01-25 2018-02-01
#> 10 1 71 2009-02-01 2012-03-10
#> # ℹ more rows
# }