derive_vars_duration: Derive Duration

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/derive_vars_duration.R

Description

Derives duration between two dates, e.g., duration of adverse events, relative day, age, ...

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
derive_vars_duration(
  dataset,
  new_var,
  new_var_unit = NULL,
  start_date,
  end_date,
  in_unit = "days",
  out_unit = "days",
  floor_in = TRUE,
  add_one = TRUE,
  trunc_out = FALSE
)

Arguments

dataset

Input dataset

The columns specified by the start_date and the end_date parameter are expected.

new_var

Name of variable to create

new_var_unit

Name of the unit variable If the parameter is not specified, no variable for the unit is created.

start_date

The start date

A date or date-time object is expected.

end_date

The end date

A date or date-time object is expected.

in_unit

Input unit

See floor_in and add_one parameter for details.

Default: 'days'

Permitted Values: 'years', 'months', 'days', 'hours', 'minutes', 'seconds'

out_unit

Output unit

The duration is derived in the specified unit

Default: 'days'

Permitted Values: 'years', 'months', 'days', 'hours', 'minutes', 'seconds'

floor_in

Round down input dates?

The input dates are round down with respect to the input unit, e.g., if the input unit is 'days', the time of the input dates is ignored.

Default: 'TRUE“

Permitted Values: TRUE, FALSE

add_one

Add one input unit?

If the duration is non-negative, one input unit is added. I.e., the duration can not be zero.

Default: TRUE Permitted Values: TRUE, FALSE

trunc_out

Return integer part

The fractional part of the duration (in output unit) is removed, i.e., the integer part is returned.

Default: FALSE

Permitted Values: TRUE, FALSE

Details

The duration is derived as time from start to end date in the specified output unit. If the end date is before the start date, the duration is negative.

Value

The input dataset with the duration and unit variable added

Author(s)

Stefan Bundfuss

See Also

compute_duration()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
data <- tibble::tribble(
  ~BRTHDT, ~RANDDT,
  lubridate::ymd("1984-09-06"), lubridate::ymd("2020-02-24")
)

derive_vars_duration(data,
  new_var = AAGE,
  new_var_unit = AAGEU,
  start_date = BRTHDT,
  end_date = RANDDT,
  out_unit = "years",
  add_one = FALSE,
  trunc_out = TRUE
)

epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.