Learn R Programming

lares (version 5.0.3)

date_feats: One Hot Encoding for Date/Time Variables (Dummy Variables)

Description

This function lets the user automatically create new columns out of a dataframe or vector with date/time variables.

Usage

date_feats(
  dates,
  drop = FALSE,
  only = NA,
  features = TRUE,
  holidays = FALSE,
  country = "Venezuela",
  currency_pair = NA,
  quiet = FALSE
)

Arguments

dates

Vector or dataframe. Non-date/time columns will be automatically ignored/extracted.

drop

Boolean. Should the original date/time columns be kept in the results? Only valid when input is a dataframe.

only

Character or vector. Which columns do you wish to process? If non are explicitly defined, all will be processed

features

Create features out of date/time columns?

holidays

Boolean. Include holidays as new columns?

country

Character or vector. For which countries should the holidays be included?

currency_pair

Character. Which currency exchange do you wish to get the history from? i.e, USD/COP, EUR/USD...

quiet

Boolean. Quiet all messages?

Value

data.frame with additional features calculated out of time or date vectors.

See Also

Other Data Wrangling: balance_data(), categ_reducer(), cleanText(), date_cuts(), formatNum(), holidays(), impute(), left(), normalize(), numericalonly(), ohe_commas(), ohse(), removenacols(), removenarows(), replaceall(), textFeats(), textTokenizer(), vector2text(), year_month(), year_week()

Other Feature Engineering: holidays(), ohse()

Other One Hot Encoding: holidays(), ohe_commas(), ohse()

Examples

Run this code
# NOT RUN {
df <- data.frame(
  dates = sample(seq(Sys.Date() - 365, Sys.Date(), by = 1), 50),
  times = sample(seq(Sys.time() - 1e7, Sys.time(), by = 1), 50)
)

# Input as a vector or dataframe
date_feats(df, drop = TRUE) %>% head(10)

# Holidays given a date range and country
# }
# NOT RUN {
hol <- date_feats(
  seq(Sys.Date() - 365, Sys.Date(), by = 1),
  holidays = TRUE,
  country = "Colombia"
)
head(hol[!is.na(hol$holidayname), ])
# }

Run the code above in your browser using DataLab