Skip to contents

This helper function replaces a pattern of "NK" in months and in days in a date, with the first day or month. The function expects that the pattern of the date is 'YYYY-MM-DD'.

Usage

clean_dates(x, unknown_pattern = "NK", unknown_replacement = "01")

Arguments

x

A character or date vector. if the input is already a date vector, the input will be returned unchanged.

unknown_pattern

Pattern to look up in the date, standard "NK". Note that the pattern will gain a prefix of "-", to avoid that years with the tag unknown_pattern tab will be replaced. Dates containing years with the unknown_pattern tag will become missing.

unknown_replacement

Replacement of the unknown pattern. Standard 01 (first day/month).

Value

A date-class vector.

Examples

clean_dates(c("2023-08-NK", "2023-NK-NK", "NK-08-01"))
#> [1] "2023-08-01" "2023-01-01" NA