timespan | R Documentation |
Calculate time span between dates
timespan(
data,
target_column = NULL,
end_date = Sys.Date(),
span_unit = c("years", "months", "weeks", "days"),
span_column_name = "span",
span_remainder_unit = NULL
)
data |
The input |
target_column |
A |
end_date |
The end date. It can be either a |
span_unit |
A |
span_column_name |
A |
span_remainder_unit |
A |
The input <data.frame>
with one or two additional columns:
or any other name chosen by the user. This will contain the calculated time span in the desired units.
a column with the number of the remaining days or weeks or months depending on the value of the 'span_remainder_unit' parameter. The star represents here the value of the 'span_column_name' argument.
# In the below example, this function is used to calculate patient's age from
# their dates of birth
# import the data, replace missing values with NA and convert date into ISO
# format
data <- readRDS(system.file("extdata", "test_df.RDS", package = "cleanepi"))
data <- data %>%
replace_missing_values(target_columns = "dateOfBirth",
na_strings = "-99") %>%
standardize_dates(target_columns = "dateOfBirth",
error_tolerance = 0.0)
# calculate the age in 'years' and return the remainder in 'months'
age <- timespan(
data = data,
target_column = "dateOfBirth",
end_date = Sys.Date(),
span_unit = "years",
span_column_name = "age_in_years",
span_remainder_unit = "months"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.