--- title: "Dates and periods" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Dates and periods} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- `vars_to_date` accepts column names or positions. Year and month produce monthly dates; year and quarter produce quarterly dates; year, month and day produce daily dates. Year alone is also supported. Month names and quarter ranges accept English and Spanish, along with Q1, T1 and I–IV labels. Output contains `date` as its first column. With `drop_vars = FALSE`, original component values remain unchanged. `.round = 'end'` selects the final day of the period, including leap-year February. `start` or NULL selects the beginning. `middle` means the 15th of the month, the 15th of a quarter's middle month, or July 1 for a year. Daily dates are not rounded. A `date` column can contain Date, POSIXt, ISO dates, numeric serials, an explicit character format, or EViews periods such as 2020M02 and 2021Q04. Do not combine `date` with component arguments. Missing components, invalid periods and impossible calendar combinations raise errors. The historical numeric origin remains 1900-01-01. For modern Excel serial dates, explicitly use `origin = '1899-12-30'`: the origin does not change automatically. Cumulative quarter labels are interpreted by their ending quarter for compatibility. ```{r} library(Dmisc) x <- data.frame(year = c(2020, 2021), month = c("Febrero", "February")) result <- vars_to_date(x, year = "year", month = "month", drop_vars = FALSE) print(result) stopifnot(identical(result$date, as.Date(c("2020-02-29", "2021-02-28")))) vars_to_date(data.frame(period = c("2020M02", "2021Q04")), date = "period") ```