simpledates: Format dates

View source: R/format.R

simpledatesR Documentation

Format dates

Description

Function will leave POSIX dates and attempt to convert dates which are in string format, excel exported numeric format or numeric format into the "best guess" date. Where vector provided with dates in more than one format will attempt to convert them all.

Usage

simpledates(x, char = NA, silent = TRUE)

Arguments

x

dates to format. Takes a single date, vectors or a column of data.

char

Optional value to return for character strings; Default is NA. Use historic date values to manage categories where date not known but label required for downstream processing.

silent

Optional suppress warning of occurrences which failed to parse. Default is TRUE.

Value

Returns input formatted as Date

Examples

# Format a single string into a date
# date <- simpledates("2020739")

# Format a data.frame column into a consistent date format
# df$column <- simpledates(df$column)

# Format all column from within a data.table where the columns
# contain the string date into date format
# for (col in (names(dt)[grepl("date", names(dt))])){
#   dt[,(col) := simpledates(dt[,get(col)])]
#  }

DHatziioanou/simpleepi documentation built on Sept. 24, 2024, 5:25 a.m.