Skip to contents

Get Variables Common Date

Usage

get_vars_common_date(
  .data,
  date_cols,
  select_method = "min",
  compared_ref_date = FALSE,
  ref_date_col = NULL,
  preferred_date_col = NULL
)

Arguments

.data

A wide format data.frame

date_cols

Character vector of date column names

select_method

Selection method if there is more than one unique non-missing date, Default: 'min' Either the minimum date ('min'), or the maximum date ('max').

compared_ref_date

A Boolean to compared the common date with the reference date if it is provided, Default: FALSE

ref_date_col

Reference date column name, Default: NULL

preferred_date_col

Preferred date when common date and reference date are different. Only applicable if compared_ref_date is TRUE.

Value

A data.frame with the appended columns:

  • COMMON_DATE Common date among the provided date columns

  • FINAL_DATE Final date after comparing with reference date if compared_ref_date is TRUE. Otherwise the same as COMMON_DATE.

  • DATE_RECORD_TYPE Record type to indicate whether the date columns are the same rowwise or not.

Details

This function is used to get a common date value across multiple date columns and compared with reference date column if it is provided. The comparison algorithm is based on rowwise operation and presented as follow:

For records that have at least one non-missing date columns based on the list of provided date columns:

  • Select one unique date value if all date columns are the same/equal.

  • Select either the minimum or maximum date based on the selection method (select_method) if at least one date column is differ from the remaining provided date columns.

The reference date column must be present for any comparison with reference date. Then, the reference date will be used for any missing common date.

Otherwise, the date will considered as missing NA.

Examples

if (FALSE) { # \dontrun{
# Please see the \code{ADNIMERGE2-PACC-SCORE} vignette
vignette(topic = "ADNIMERGE2-PACC-SCORE", package = "ADNIMERGE2")
} # }