![](../logo.png)
Reorder Columns Based on Assessment Dates
Source:R/get_morbidity_events.R
reorder_columns_based_on_date.Rd
This function reorders all columns in a dataframe after the third column based on their corresponding assessment dates.
Details
The function assumes that there is a row in the dataframe where the `side_effect` column is "assessment_date" and the subsequent columns contain the corresponding assessment dates. The function extracts these dates, sorts the columns accordingly, and returns the reordered dataframe.
Examples
if (FALSE) { # \dontrun{
df <- tibble::tibble(
embrace_id = c("AAR2005", "AAR2005"),
side_effect = c("general_comments", "assessment_date"),
`Diagnosis & Treatment` = c(NA, NA),
`3m` = c(NA, "2017-01-01"),
`6m` = c(NA, "2017-07-01"),
`9m` = c(NA, "2017-10-01")
)
reordered_df <- reorder_columns_based_on_date(df)
} # }