View source: R/aggregate_los.R
aggregate_los | R Documentation |
Aggregate duration of record level events
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"
)
start_date |
Date. Event start date |
end_date |
Date. Event end date |
level |
Character. Desired level. Passed to 'by' in |
strata |
Atomic. Population strata |
count_id |
Atomic. If provided the unique count of |
event_id |
Atomic. If provided the unique count of |
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 |
A data frame
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'
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.