aggregate_los: Aggregate duration of record level events

View source: R/aggregate_los.R

aggregate_losR Documentation

Aggregate duration of record level events

Description

Aggregate duration of record level events

Usage

aggregate_los(
  start_date,
  end_date,
  level = diff(range(start_date, end_date)),
  strata = NULL,
  count_id = NULL,
  event_id = NULL,
  start_date_point = "start_of_day",
  fill = FALSE,
  silent = TRUE,
  units = "days"
)

Arguments

start_date

Date. Event start date

end_date

Date. Event end date

level

Character. Desired level. Passed to 'by' in seq. Options include all accepted in seq(..., by = XX)

strata

Atomic. Population strata

count_id

Atomic. If provided the unique count of count_id per iteration (batch) is included

event_id

Atomic. If provided the unique count of event_id per iteration (batch) is included

start_date_point

Character|Date. Start point to begin aggregation. Acceptable options are "start_of_day", "start_of_month", "start_of_quarter" or "start_of_year". Alternatively, a specific date can be provided.

fill

Logical. If TRUE, place holders are included if there is no occurrence of the event within the batch of the loop.

silent

Logical. Print (or not) current iteration of loop.

units

Character. Desired unit for level. Passed to 'by' in seq. Options include all accepted in seq(..., by = XX)

Value

A data frame

Examples

dfr <- data.frame(
  start_date = as.Date(c('2024-05-28', '2024-05-05', '2024-06-01')),
  end_date = as.Date(c('2024-06-05', '2024-05-11', '2024-06-20')),
  strata = c('A', 'A', 'B'))

dfr$duration <- difftime(dfr$end_date, dfr$start_date, 'days')

dfr

aggregate_los(
  start_date = dfr$start_date,
  end_date = dfr$end_date
)

aggregate_los(
  start_date = dfr$start_date,
  end_date = dfr$end_date,
  level = 'month'
)

aggregate_los(
  start_date = dfr$start_date,
  end_date = dfr$end_date,
  level = 'month',
  strata = dfr$strata
)

aggregate_los(
  start_date = dfr$start_date,
  end_date = dfr$end_date,
  level = 'month',
  strata = dfr$strata,
  start_date_point = 'start_of_month'
)

aggregate_los(
  start_date = dfr$start_date,
  end_date = dfr$end_date,
  level = 'month',
  strata = dfr$strata,
  start_date_point = 'start_of_month',
  units = 'weeks'
)

aggregate_los(
  start_date = as.POSIXct(dfr$start_date),
  end_date = as.POSIXct(dfr$end_date),
  level = 'month',
  strata = dfr$strata,
  start_date_point = 'start_of_month',
  units = 'mins'
)

aggregate_los(
  start_date = dfr$start_date,
  end_date = dfr$end_date,
  level = 'day',
  strata = dfr$strata,
  start_date_point = 'start_of_month',
  units = 'days'
)


OlisaNsonwu/jurithy documentation built on Aug. 31, 2024, 12:20 a.m.