library(dplyr)
library(tidyquant)
library(timetk)
options(max.print = 50)
# ---- DATE ----
# Start + End, Guesses by = "day"
tk_make_timeseries("2017-01-01", "2017-12-31")
# Just Start
tk_make_timeseries("2017") # Same result
# Only dates in February, 2017
tk_make_timeseries("2017-02")
# Start + Length Out, Guesses by = "day"
tk_make_timeseries("2012", length_out = 6) # Guesses by = "day"
# Start + By + Length Out, Spacing 6 observations by monthly interval
tk_make_timeseries("2012", by = "1 month", length_out = 6)
# Start + By + Length Out, Phrase "1 year 6 months"
tk_make_timeseries("2012", by = "1 month",
length_out = "1 year 6 months", include_endpoints = FALSE)
# Going in Reverse, End + Length Out
tk_make_timeseries(end_date = "2012-01-01", by = "1 month",
length_out = "1 year 6 months", include_endpoints = FALSE)
# ---- DATE-TIME ----
# Start + End, Guesses by second
tk_make_timeseries("2016-01-01 01:01:02", "2016-01-01 01:01:04")
# Date-Time Sequence - By 10 Minutes
# - Converts to date-time automatically & applies 10-min interval
tk_make_timeseries("2017-01-01", "2017-01-02", by = "10 min")
# --- REMOVE / INCLUDE ENDPOINTS ----
# Last value in this case is desired
tk_make_timeseries("2017-01-01", by = "30 min", length_out = "6 hours")
# Last value in monthly case is not wanted
tk_make_timeseries("2012-01-01", by = "1 month",
length_out = "12 months",
include_endpoints = FALSE) # Removes unnecessary last value
# ---- SKIP & INSERT VALUES ----
tk_make_timeseries(
"2011-01-01", length_out = 5,
skip_values = "2011-01-05",
insert_values = "2011-01-06"
)
Run the code above in your browser using DataLab