vars_to_date: Multiple variables to unique date variable *[Experimental]*

View source: R/vars_to_date.R

vars_to_dateR Documentation

Multiple variables to unique date variable [Experimental]

Description

Multiple variables to unique date variable [Experimental]

Usage

vars_to_date(
  tbl,
  year = NULL,
  quarter = NULL,
  month = NULL,
  day = NULL,
  date = NULL,
  drop_vars = TRUE,
  clean_names = FALSE,
  date_format = "%d-%m-%y",
  origin = "1900-01-01",
  .round = c("end", "middle", "start")
)

Arguments

tbl

data.frame or tbl connection

year

year variable position or name

quarter

quarter variable position or name

month

month variable position or name

day

day variable position or name

date

a variable name or position containing a like date format

drop_vars

indicates if variables should be dropped

clean_names

indicates if all variable names should be cleaned

date_format

actual date format of variable in date argument

origin

base date for variable convertion to date

.round

indicates if the date should be rounded to the end, middle or start of the period

Value

tbl a new data.frame with the compute variable

Examples

tbl <- data.frame(
  year = rep("2021", 12),
  month = month.name,
  day = sample(1:3, 12, TRUE),
  value = sample(100:1000, 12, TRUE)
)

tbl

vars_to_date(tbl, year = 1, month = 2, day = 3)

# and supports various frequencies and date formats

tbl <- data.frame(
  year = rep("2021", 12),
  quarter = sample(
            c(
              "Enero-Marzo",
              "Abril-Junio",
              "Julio-Septiembre",
              "Octubre-Diciembre"
             ),
            12,
            TRUE
           ),
  value = sample(100:1000, 12, TRUE)
)

tbl

vars_to_date(tbl, year = 1, quarter = 2)

drdsdaniel/Dmisc documentation built on Oct. 23, 2024, 9:28 p.m.