
Compute the number of days of prior observation in the current observation period at a certain date
Source:R/addDemographics.R
addPriorObservation.RdCompute the number of days of prior observation in the current observation period at a certain date
Usage
addPriorObservation(
x,
indexDate = "cohort_start_date",
priorObservationName = "prior_observation",
priorObservationType = "days",
name = NULL,
type = "numeric"
)Arguments
- x
A table containing individuals in a CDM reference.
- indexDate
Name of a date column in
x, or a single date to use for all rows, used as the reference date.- priorObservationName
Name of the prior-observation column to add.
- priorObservationType
Whether to return a
"date"or a number of"days".- 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)
cdm <- mockPatientProfiles(source = "duckdb")
cdm$cohort1 |>
addPriorObservation()
#> # A query: ?? x 5
#> # 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 2 9 1927-11-07 1931-09-05
#> 2 2 5 1978-09-15 1989-04-04
#> 3 3 2 1920-08-06 1921-07-25
#> 4 2 4 1980-05-03 1981-05-15
#> 5 3 10 1995-06-01 1995-08-01
#> 6 2 6 1958-03-17 1959-02-07
#> 7 2 1 1936-07-14 1958-02-23
#> 8 3 3 1931-05-03 1932-04-08
#> 9 1 7 1945-10-06 1956-12-22
#> 10 3 8 1995-06-10 2017-07-09
#> # ℹ 1 more variable: prior_observation <dbl>
# }