tk_index()
is used to extract the date or datetime index from various
time series objects, models and forecasts.
The method can be used on tbl
, xts
, zoo
, zooreg
, and ts
objects.
The method can additionally be used on forecast
objects and a number of
objects generated by modeling functions such as Arima
, ets
, and HoltWinters
classes to get the index of the underlying data.
The boolean timetk_idx
argument is applicable to regularized time series objects
such as ts
and zooreg
classes that have both a regularized index and potentially
a "timetk index" (a time-based attribute).
When set to FALSE
the regularized index is returned.
When set to TRUE
the time-based timetk index is returned if present.
has_timetk_idx()
is used to determine if the object has a "timetk index" attribute
and can thus benefit from the tk_index(timetk_idx = TRUE)
.
TRUE
indicates the "timetk index" attribute is present.
FALSE
indicates the "timetk index" attribute is not present.
If FALSE
, the tk_index()
function will return the default index for the data type.
Important Note: To gain the benefit of timetk_idx
the time series
must have a timetk index.
Use has_timetk_idx
to determine if the object has a timetk index.
This is particularly important for ts
objects, which
by default do not contain a time-based index and therefore must be coerced from time-based
objects such as tbl
, xts
, or zoo
using the tk_ts()
function in order
to get the "timetk index" attribute.
Refer to tk_ts()
for creating persistent date / datetime index
during coercion to ts
.