Description Usage Arguments Details Value Author(s)
View source: R/convert_dates.R
Converts messy nonstandarized Excel dates to consistent date formatting.
1 2 3 4 5 6 7 8 | convert_dates(
dt,
excel_file = NULL,
file_ext = NULL,
add_time = 0,
date_origin = "1899-12-30",
output_format = "iso8601"
)
|
dt |
Data.frame for which the date conversions should be made. The date column has to be named as |
excel_file |
path to the Excel file where the dates originate from. Can be left empty, if the date conversion should be done for other type of files (for example .csv or .txt). |
file_ext |
Extension of the data file. Can be left empty, if |
add_time |
Hours to be added to the ISO 8601 |
date_origin |
The origin for recorded dates in the Excel sheet in "YYYY-MM-DD" format. See Details. |
output_format |
Character string specifying in which format the date information should be returned. Options: |
date_col |
Not implemented yet. Name of the column, which contains dates to be converted. |
Large (biological) datasets are often recorded on Excel sheets with the file going around several computers using different operating systems and locales. This often leads to dates being recorded in multiple formats from text strings, to various Excel date formats and numeric date codes for which the origin date may vary. This function attempts to fix such inconsistensies in date formats and returns the dates as a character column representing ISO 8601 dates. The function is still experimental and due to the many ways of recording dates in Excel, the outcome might differ from the desired outcome. Please check each date returned by the function and report any inconsistencies so that the function can be improved.
The add_time
argument can be used to add or subtract hours from the output, if the times do not match with those in the Excel sheet. This can be helpful if your locale or operating system causes an offset between recorded dates.
The function also works for other types of messy dates than those recorded in Excel sheets.
Returns a data.frame equal to dt
with date_col
as character representing ISO 8601 dates.
Mikko Vihtakari
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.