fix_dates: Clean up messy date columns

Description Usage Arguments Value Examples

View source: R/fix_dates.R

Description

Cleans up a dataframe object which has date columns entered via a free-text box (possibly by different users) and are therefore in a non-standardised format. Supports numerous seperators including /,- or space. Supports all-numeric, abbreviation or long-hand month notation. Where day of the month has not been supplied, the first day of the month is imputed. When day, month and year is given either DMY or YMD is assumed; the US system of MDY is not supported.

Usage

1
fix_dates(df, col.names)

Arguments

df

A dataframe object with messy date column(s)

col.names

Character vector of names of columns of messy date data

Value

A dataframe object. Selected columns are of type Date

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
bad.dates <- data.frame(id = seq(5),
                        some.dates = c("02/05/92",
                                       "01-04-2020",
                                       "1996/05/01",
                                       "2020-05-01",
                                       "02-04-96"),
                        some.more.dates = c("2015",
                                            "02/05/00",
                                            "05/1990",
                                            "2012-08",
                                            "jan 2020"))
fixed.df <- fix_dates(bad.dates, c("some.dates", "some.more.dates"))

VallejosGroup/rvallejo documentation built on Jan. 29, 2021, 2:41 p.m.