Retrieve or replace the index of an object.
Value
The index of the object (a Date vector when the input data
carried one, otherwise an integer sequence). The replacement form returns the
modified object.
Details
If you do not specify an index for the estimation, the function
generates a pseudo-index, a sequential numeric series. After the estimation you
can use index() to retrieve the index or index<-() to replace it. The index
can be numeric or Date.
Examples
# \donttest{
# A plain numeric vector gets a pseudo-index (1, 2, 3, ...)
rsim <- radf(sim_data)
head(index(rsim))
#> [1] 1 2 3 4 5 6
# A data.frame with a Date column uses it as the index automatically
rsim_wdate <- radf(sim_data_wdate)
#> Using `date` as index variable.
head(index(rsim_wdate))
#> [1] "2000-01-01" "2000-02-01" "2000-03-01" "2000-04-01" "2000-05-01"
#> [6] "2000-06-01"
class(index(rsim_wdate))
#> [1] "Date"
# autoplot() uses index() internally for the x-axis
autoplot(rsim_wdate)
#> Using precomputed critical values for `cv`.
# Replace the index, e.g. with a custom Date sequence
index(rsim) <- seq(as.Date("2000-01-01"), by = "month", length.out = length(index(rsim)))
head(index(rsim))
#> [1] "2000-01-01" "2000-02-01" "2000-03-01" "2000-04-01" "2000-05-01"
#> [6] "2000-06-01"
autoplot(rsim)
#> Using precomputed critical values for `cv`.
# }
