library(timetk)
# ---- LOCATING A DATE N-PERIODS IN FUTURE / PAST ----
# Forward (Plus Time)
"2021" %+time% "1 hour 34 seconds"
"2021" %+time% "3 months"
"2021" %+time% "1 year 3 months 6 days"
# Backward (Minus Time)
"2021" %-time% "1 hour 34 seconds"
"2021" %-time% "3 months"
"2021" %-time% "1 year 3 months 6 days"
# ---- INDEX SHIFTING ----
index_daily <- tk_make_timeseries("2016", "2016-02-01")
# ADD TIME
# - Note `NA` values created where a daily dates aren't possible
# (e.g. Feb 29 & 30, 2016 doesn't exist).
index_daily %+time% "1 month"
# Subtracting Time
index_daily %-time% "1 month"
Run the code above in your browser using DataLab