Description Usage Arguments Value Examples
View source: R/assign_timepoint.R
Given a data set that has a measure collected over time and you want to extract, for example the 3 month measurement, this function will find the measure closest to 3 months within a defined window.
1 2 3 4 5 6 7 8 9 10 | assign_timepoint(
data,
id,
ref_date,
measure_date,
timepoints,
windows,
time_units = c("days", "weeks", "months", "years"),
new_var = "timepoint"
)
|
data |
data frame |
id |
id variable name, such as |
ref_date |
baseline or reference date column name |
measure_date |
date the measure was collected |
timepoints |
vector of timepoint to identify |
windows |
list of windows around a timepoint that are acceptable |
time_units |
one of |
new_var |
name of new variable, default is |
data frame passed in data
with additional column new_var
1 2 3 4 5 6 7 8 9 10 11 12 13 | ggplot2::economics_long %>%
dplyr::group_by(variable) %>%
dplyr::mutate(min_date = min(date)) %>%
dplyr::ungroup() %>%
assign_timepoint(
id = "variable",
ref_date = "min_date",
measure_date = "date",
timepoints = c(6, 12, 24),
windows = list(c(-2, 2), c(-2, 2), c(-2, 2)),
time_units = "months"
) %>%
dplyr::filter(!is.na(timepoint))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.