Skip to contents

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,
  append = FALSE,
  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

append

Boolean. Append results to existing data.frame? If FALSE, only calculated values will be returned.

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. Keep quiet? If not, informative messages will be shown.

Value

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

Examples

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, quiet = TRUE) %>% head(10)
#> # A tibble: 10 × 18
#>    dates_year dates_month dates_day dates_week dates_weekday dates_weekend
#>         <dbl>       <dbl>     <int>      <dbl> <chr>         <lgl>        
#>  1       2026           5        21         21 Thu           FALSE        
#>  2       2025          12         7         49 Sun           TRUE         
#>  3       2026           6         6         23 Sat           TRUE         
#>  4       2026           9        25         39 Fri           FALSE        
#>  5       2026           3        21         12 Sat           TRUE         
#>  6       2026           9        18         38 Fri           FALSE        
#>  7       2026           7        10         28 Fri           FALSE        
#>  8       2026           7        25         30 Sat           TRUE         
#>  9       2026          11        23         47 Mon           FALSE        
#> 10       2026           4        25         17 Sat           TRUE         
#> # ℹ 12 more variables: dates_year_day <int>, times_year <dbl>,
#> #   times_month <dbl>, times_day <int>, times_week <dbl>, times_weekday <chr>,
#> #   times_weekend <lgl>, times_year_day <int>, times_hour <int>,
#> #   times_minute <int>, times_minutes <int>, times_second <dbl>

# Holidays given a date range and country
if (FALSE) { # \dontrun{
hol <- date_feats(
  seq(Sys.Date() - 365, Sys.Date(), by = 1),
  holidays = TRUE,
  country = "Venezuela"
)
head(hol[!is.na(hol$holiday_name), ])
} # }