ts_frequency: Change Frequency

View source: R/ts_frequency.R

ts_frequencyR Documentation

Change Frequency

Description

Changes the frequency of a time series. By default, incomplete periods of regular series are omitted.

Usage

ts_frequency(
  x,
  to = c("year", "quarter", "month", "week", "day", "hour", "min", "sec"),
  aggregate = "mean",
  na.rm = FALSE
)

Arguments

x

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

to

desired frequency, either a character string ("year", "quarter", "month") or an integer (1, 4, 12).

aggregate

character string, or function. Either "mean", "sum", "first", or "last", or any aggregate function, such as base::mean().

na.rm

logical, if TRUE, incomplete periods are aggregated as well. For irregular series, incomplete periods are always aggregated.

Details

The tempdisagg package can convert low frequency to high frequency data and has support for ts-boxable objects. See vignette("hf-disagg", package = "tempdisagg").

Value

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

Examples


ts_frequency(cbind(mdeaths, fdeaths), "year", "sum")
ts_frequency(cbind(mdeaths, fdeaths), "quarter", "last")

ts_frequency(AirPassengers, 4, "sum")

# Note that incomplete years are omited by default
ts_frequency(EuStockMarkets, "year")
ts_frequency(EuStockMarkets, "year", na.rm = TRUE)


tsbox documentation built on Oct. 23, 2024, 1:07 a.m.