clean_date: Cleans different formats of unclean date strings

Description Usage Arguments Value Warning Examples

View source: R/clean_date.R

Description

Cleans different formats of date strings and converts them to a uniform date format "%Y-%m-%d" as returned by as.Date(). Year must be in last position. If it encounters a swap in month and day position it swaps them around.

Usage

1
clean_date(date_vec, unresolved = FALSE)

Arguments

date_vec

A vector of strings

unresolved

TRUE returns a list including a vector of unresolved values.

Value

If unresolved is set to true returns a list containing two elements: $Date is a vector of strings with the cleaned or otherwise untouched input data and $unresolved is a logical vector with FALSE if a value was changed and TRUE otherwise. If unresolved is false, only the date vector will be returned.

Warning

Produces NA if year is in first position and date does not follow the formatting convention of as.Date.

Examples

1
2
3
4
5
6
7
8
9
clean_date("24.12.2000")

clean_date("24/12/00")

clean_date("12/24/00")

clean_date("12 /2 /2016")

clean_date("12 /2 /2016", unresolved=TRUE)$unresolved

aotearoastats/datacleanr documentation built on May 6, 2019, 9:49 p.m.