View source: R/fix_date_char.R
| fix_date_char | R Documentation |
Date classConverts a character vector (or single character object) from inconsistently
formatted dates to R's Date class. Supports numerous separators
including /, -, ., or space. Supports numeric, abbreviation, or long-hand
month notation in multiple languages (English, French, German, Spanish,
Portuguese, Russian, Czech, Slovak, Indonesian). Where day of the month has
not been supplied, the first day of the month is imputed by default. Either
DMY or YMD is assumed by default. However, the US system of MDY is supported
via the format argument.
fix_date_char(
dates,
day.impute = 1,
month.impute = 7,
format = "dmy",
excel = FALSE,
roman.numeral = FALSE
)
This function intelligently parses dates by:
Handling mixed separators within the same dataset
Recognizing month names in multiple languages
Converting Roman numeral months (experimental)
Processing Excel serial date numbers
Automatically detecting YMD format when year appears first
Smart imputation of missing date components with user control
For comprehensive examples and advanced usage, see browseVignettes("datefixR")
or the package README at https://docs.ropensci.org/datefixR/.
A vector of elements belonging to R's built in Date class
with the following format yyyy-mm-dd.
fix_date_df for data frame columns with date data.
For detailed examples and usage patterns, see:
Package vignette: browseVignettes("datefixR")
Online documentation: https://docs.ropensci.org/datefixR/articles/datefixR.html
Package README: https://docs.ropensci.org/datefixR/
# Basic usage
bad.date <- "02 03 2021"
fix_date_char(bad.date)
# Multiple formats with different separators
mixed_dates <- c(
"02/05/92", # slash separator, 2-digit year
"2020-may-01", # hyphen separator, text month
"1996.05.01", # dot separator
"02 04 96", # space separator
"le 3 mars 2013" # French format
)
fix_date_char(mixed_dates)
# Text months in different languages
text_months <- c(
"15 January 2020", # English
"15 janvier 2020", # French
"15 Januar 2020", # German
"15 enero 2020", # Spanish
"15 de janeiro de 2020" # Portuguese
)
fix_date_char(text_months)
# Roman numeral months (experimental)
roman_dates <- c("15.VII.2023", "3.XII.1999", "1.I.2000")
fix_date_char(roman_dates, roman.numeral = TRUE)
# Excel serial numbers
excel_serials <- c("44197", "44927") # Excel dates
fix_date_char(excel_serials, excel = TRUE)
# Two-digit years (automatic century detection)
two_digit_years <- c("15/03/99", "15/03/25", "15/03/50")
fix_date_char(two_digit_years) # 1999, 2025, 1950
# MDY format (US style)
us_dates <- c("12/25/2023", "07/04/1776", "02/29/2020")
fix_date_char(us_dates, format = "mdy")
# Incomplete dates with custom imputation
incomplete <- c("2023", "March 2022", "June 2021")
fix_date_char(incomplete, day.impute = 15, month.impute = 6)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.