clean_dates | R Documentation |
Applies a dictionary of value-replacement pairs and a conversion function
(defaults to parse_dates
) to clean and standardize values of date
variables. To use this approach the date columns of the original dataset
should generally be imported as type "text" or "character" so that non-valid
values are not automatically coerced to missing values on import.
clean_dates(x, vars, vars_id, dict_clean = NULL, fn = parse_dates, na = ".na")
x |
A data frame with one or more date columns to clean |
vars |
Names of date columns within |
vars_id |
Vector of one or more ID columns within |
dict_clean |
Optional dictionary of value-replacement pairs (e.g.
produced by a prior run of |
fn |
Function to parse raw date values. Defaults to |
na |
Keyword to use within column "replacement" for values that should
be converted to |
The original data frame x
but with cleaned versions of the date variables
specified in argument vars
# load example dataset and cleaning dictionary
data(ll1)
data(clean_dates1)
# clean dates using only date coercion function
clean_dates(
ll1,
vars = c("date_onset", "date_admit", "date_exit"),
vars_id = "id"
)
# clean dates using dictionary and coercion function
clean_dates(
ll1,
vars = c("date_onset", "date_admit", "date_exit"),
vars_id = "id",
dict_clean = clean_dates1
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.