knitr::opts_chunk$set( message = FALSE, warning = FALSE, fig.width = 8, fig.height = 4.5, fig.align = 'center', out.width='95%', dpi = 100 ) # devtools::load_all() # Travis CI fails on load_all()

**Creating and modifying date sequences** is critical to machine learning projects. We discuss:

- Making a Time Series Sequence:
`tk_make_timeseries()`

- Making a Future Sequence:
`tk_make_future_timeseries()`

- Holiday & Weekday/Weekend Sequences

Before we get started, load the following packages.

library(dplyr) library(timetk)

`tk_make_timeseries()`

improves on the `seq.Date()`

and `seq.POSIXt()`

functions by simplifying into 1 function. Intelligently handles character dates and logical assumptions based on user inputs.

**By Day**

- Can use
`by = "day"`

or leave blank. `include_endpoints = FALSE`

removes the last value so your series is only 7 observations.

# Selects by day automatically tk_make_timeseries("2011", length_out = "7 days", include_endpoints = FALSE)

**By 2 Seconds**

- Can use
`by = "2 sec"`

to adjust the interval width. `include_endpoints = TRUE`

keeps the last value the series ends on the 6th second.

# Guesses by second tk_make_timeseries("2016", by = "2 sec", length_out = "6 seconds")

**Length Out = 1 year 6 months**

`length_out = "1 year 6 months"`

- Can include complex expressions like "1 year 4 months 6 days".

tk_make_timeseries("2012-07", by = "1 month", length_out = "1 year 6 months", include_endpoints = FALSE)

**Go In Reverse**

- To go in reverse, just use
`end_date`

as where you want the series to end.

tk_make_timeseries(end_date = "2012-07-01", by = "1 month", length_out = "1 year 6 months")

A common operation is to make a future time series sequence that mimics an existing. This is what `tk_make_future_timeseries()`

is for.

Suppose we have an existing time index.

idx <- tk_make_timeseries("2012", by = "3 months", length_out = "2 years", include_endpoints = FALSE) idx

**Make a Future Time Series from an Existing**

We can create a future time sequence from the existing sequence using `tk_make_future_timeseries()`

.

tk_make_future_timeseries(idx, length_out = "2 years")

**Make weekday sequence removing holidays**

- Result is 252 days.

idx <- tk_make_weekday_sequence("2012", remove_weekends = TRUE, remove_holidays = TRUE, calendar = "NYSE") tk_get_timeseries_summary(idx)

**Which holidays were removed?**

- NYSE Trading holidays which are days most businesses observe

tk_make_holiday_sequence("2012", calendar = "NYSE")

**Make future index removing holidays**

holidays <- tk_make_holiday_sequence( start_date = "2013-01-01", end_date = "2013-12-31", calendar = "NYSE") idx_future <- idx %>% tk_make_future_timeseries(length_out = "1 year", inspect_weekdays = TRUE, skip_values = holidays) tk_get_timeseries_summary(idx_future)

*My Talk on High-Performance Time Series Forecasting*

Time series is changing. **Businesses now need 10,000+ time series forecasts every day.**

**High-Performance Forecasting Systems will save companies MILLIONS of dollars.** Imagine what will happen to your career if you can provide your organization a "High-Performance Time Series Forecasting System" (HPTSF System).

I teach how to build a HPTFS System in my **High-Performance Time Series Forecasting Course**. If interested in learning Scalable High-Performance Forecasting Strategies then take my course. You will learn:

- Time Series Machine Learning (cutting-edge) with
`Modeltime`

- 30+ Models (Prophet, ARIMA, XGBoost, Random Forest, & many more) - NEW - Deep Learning with
`GluonTS`

(Competition Winners) - Time Series Preprocessing, Noise Reduction, & Anomaly Detection
- Feature engineering using lagged variables & external regressors
- Hyperparameter Tuning
- Time series cross-validation
- Ensembling Multiple Machine Learning & Univariate Modeling Techniques (Competition Winner)
- Scalable Forecasting - Forecast 1000+ time series in parallel
- and more.

Unlock the High-Performance Time Series Forecasting Course

**Any scripts or data that you put into this service are public.**

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.