ts_frequency: Change Frequency

Description Usage Arguments Value Examples

View source: R/ts_frequency.R

Description

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

Usage

1
ts_frequency(x, to = "year", aggregate = "mean", na.rm = FALSE)

Arguments

x

ts-boxable time series, an object of class ts, xts, zoo, 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.

Value

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

Examples

1
2
3
4
5
6
7
8
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 April 30, 2020, 1:05 a.m.