
It creates a column with the field of a desired intersection
Source:R/addCohortIntersect.R
addCohortIntersectField.RdIt creates a column with the field of a desired intersection
Arguments
- x
A table containing individuals in a CDM reference.
- targetCohortTable
Name of the cohort table to intersect with.
- field
Name or names of columns in the target tables to add to
x.- targetCohortId
Cohort definition IDs to include from
targetCohortTable. IfNULL, all cohorts are included.- indexDate
Name of a date column in
x, or a single date to use for all rows, used as the reference date.- censorDate
Date or name of a date column in
xon which to censor follow-up. IfNULL, no censoring is applied.- targetDate
Name or names of date columns in the target tables to use for the intersection.
- order
Which record to use when multiple records occur in a window:
"first"or"last".- window
Window or windows of time relative to
indexDateto consider.- nameStyle
Naming pattern for the added column or columns. It should include the required formatting variables. If more than one
tableNameis provided, it must include{table_name}.- name
Name of the new table. If
NULL, a temporary table is returned.- type
Type of the created column(s). Counts, days, age, and observation durations can be
"numeric"or"integer". Flag columns can also be"logical". Field columns can use"auto"to preserve the source type, or can be converted to"numeric","integer","logical", or"character".
Examples
# \donttest{
library(PatientProfiles)
library(dplyr)
cdm <- mockPatientProfiles(source = "duckdb")
#> Warning: There are observation period end dates after the current date: 2026-07-24
#> ℹ The latest max observation period end date found is 2028-07-21
cdm$cohort2 <- cdm$cohort2 |>
mutate(even = if_else(subject_id %% 2, "yes", "no")) |>
compute(name = "cohort2")
cdm$cohort1 |>
addCohortIntersectFlag(
targetCohortTable = "cohort2"
)
#> # A query: ?? x 7
#> # Database: DuckDB 1.5.4 [unknown@Linux 6.17.0-1020-azure:R 4.6.1/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 1 6 1945-01-10 1946-03-23
#> 2 2 10 1960-01-11 1963-09-20
#> 3 1 1 1964-12-22 1978-04-03
#> 4 3 3 1970-12-05 1976-09-10
#> 5 1 9 1983-02-27 2005-08-08
#> 6 1 2 1982-05-26 1998-12-12
#> 7 2 7 1965-09-17 1968-09-05
#> 8 1 5 1938-03-26 1938-04-06
#> 9 1 8 1959-12-18 1960-10-30
#> 10 2 4 1956-01-11 1957-08-07
#> # ℹ 3 more variables: cohort_3_0_to_inf <dbl>, cohort_1_0_to_inf <dbl>,
#> # cohort_2_0_to_inf <dbl>
# }