ts_pcy and ts_diffy calculate the percentage change rate and the difference compared to the previous period, ts_pcy and ts_diffy calculate compared to the same period of the previous year.

ts_pc(x)

ts_diff(x)

ts_pcy(x)

ts_diffy(x)

Arguments

x

ts-boxable time series, an object of class ts, xts, zoo, data.frame, data.table, tbl, tbl_ts, tbl_time, or timeSeries.

Value

a ts-boxable time series, with the same class as the input.

Examples

head(ts_diff(ts_c(fdeaths, mdeaths)))
#> fdeaths mdeaths #> Feb 1974 -212 -271 #> Mar 1974 138 14 #> Apr 1974 -150 0 #> May 1974 -155 -385 #> Jun 1974 -116 -243 #> Jul 1974 35 31
head(ts_pc(ts_c(fdeaths, mdeaths)))
#> fdeaths mdeaths #> Feb 1974 -23.52941 -12.6991565 #> Mar 1974 20.02903 0.7514761 #> Apr 1974 -18.13785 0.0000000 #> May 1974 -22.89513 -20.5114544 #> Jun 1974 -22.22222 -16.2868633 #> Jul 1974 8.62069 2.4819856
head(ts_pcy(ts_c(fdeaths, mdeaths)))
#> fdeaths mdeaths #> Jan 1975 -7.880133 -1.452671 #> Feb 1975 9.143687 14.707461 #> Mar 1975 -5.078597 14.704315 #> Apr 1975 -1.920236 -2.344166 #> May 1975 -10.536398 -5.965147 #> Jun 1975 7.881773 3.122498
head(ts_diffy(ts_c(fdeaths, mdeaths)))
#> fdeaths mdeaths #> Jan 1975 -71 -31 #> Feb 1975 63 274 #> Mar 1975 -42 276 #> Apr 1975 -13 -44 #> May 1975 -55 -89 #> Jun 1975 32 39