stldf: Get trend, seasonal, remainder for a vector that has...

View source: R/btools_dplyrtools.r

stldfR Documentation

Get trend, seasonal, remainder for a vector that has time-series data

Description

stldf get trend, seasonal, remainder for a vector that has time-series data

Usage

stldf(vec, freq)

Arguments

vec

Numeric vector with time-series data. No default.

freq

Frequency of the data. Numeric. Should be 4 (quarterly) or 12 (monthly). No default.

Details

Returns a data frame with 3 columns: trend, seasonal, remainder. Very little error checking. Useful after dplyr's group_by, in do command, which requires data frame input. Make sure data are sorted by time before using.

Value

Data frame with 3 columns: trend, seasonal, remainder

Examples

library(bdata) # so that spop.q is available
library(dplyr)
spop.q %>%
    group_by(stabbr) %>%
    dplyr::arrange(date) %>% # BE SURE DATA HAVE BEEN SORTED BY DATE WITHIN GROUPING VARS!!!
    do(cbind(., stldf(.$value, 4)))

donboyd5/btools documentation built on Jan. 7, 2023, 10:47 p.m.