compute_duration: Derive Duration

Description Usage Arguments Details Value Author(s) Examples

View source: R/compute_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
compute_duration(
  start_date,
  end_date,
  in_unit = "days",
  out_unit = "days",
  floor_in = TRUE,
  add_one = TRUE,
  trunc_out = FALSE
)

Arguments

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', 'weeks', '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 duration between the two date in the specified unit

Author(s)

Stefan Bundfuss

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# derive duration in days (integer), i.e., relative day
compute_duration(
  start_date = lubridate::ymd_hms("2020-12-06T15:00:00"),
  end_date = lubridate::ymd_hms("2020-12-24T08:15:00")
)

# derive duration in days (float)
compute_duration(
  start_date = lubridate::ymd_hms("2020-12-06T15:00:00"),
  end_date = lubridate::ymd_hms("2020-12-24T08:15:00"),
  floor_in = FALSE,
  add_one = FALSE
)

# derive age
compute_duration(
  start_date = lubridate::ymd("1984-09-06"),
  end_date = lubridate::ymd("2020-02-24"),
  trunc_out = TRUE,
  out_unit = "years",
  add_one = FALSE
)

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