simpledates | R Documentation |
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.
simpledates(x, char = NA, silent = TRUE)
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. |
Returns input formatted as Date
# 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)])]
# }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.