Learn R Programming

gseries (version 3.0.2)

time_values_conv: Time values conversion functions

Description

Time values conversion functions used internally by other gseries functions.

Usage

gs.time2year(ts)

gs.time2per(ts)

gs.time2str(ts, sep = "-")

Value

gs.time2year() returns an integer vector of the "nearest" year (time unit) values. This function is the equivalent of stats::cycle() for time unit values.

gs.time2per() returns an integer vector of the period (cycle) values (see stats::cycle()).

gs.time2str() returns a character vector corresponding to gs.time2year(ts) if stats::frequency(ts) == 1

or gs.time2year(ts) and gs.time2per(ts) separated with sep otherwise.

Arguments

ts

(mandatory)

Time series (object of class "ts" or "mts").

sep

(optional)

String (character constant) specifying the separator to use between the year and period values.

Default value is sep = "-".

See Also

ts_to_tsDF() ts_to_bmkDF() gs.build_proc_grps()

Examples

Run this code
# Dummy monthly time series 
mth_ts <- ts(rep(NA, 15), start = c(2019, 1), frequency = 12)
mth_ts
gs.time2year(mth_ts)
gs.time2per(mth_ts)
gs.time2str(mth_ts)
gs.time2str(mth_ts, sep = "m")

# Dummy quarterly time series 
qtr_ts <- ts(rep(NA, 5), start = c(2019, 1), frequency = 4)
qtr_ts
gs.time2year(qtr_ts)
gs.time2per(qtr_ts)
gs.time2str(qtr_ts)
gs.time2str(qtr_ts, sep = "q")

Run the code above in your browser using DataLab