decompose_ts: Simple time series decomposition

View source: R/decompose_ts.R

decompose_tsR Documentation

Simple time series decomposition

Description

Decomposes a time series into trend, seasonal, and residual components using simple moving averages and group means. The function returns the residual component (or the original series with trend removed) to simplify analysis.

Usage

decompose_ts(data, cols = NULL, date_col = NULL,
             period = "month", method = "additive", verbose = FALSE)

Arguments

data

A data frame with a time column.

cols

Column indices or names to decompose.

date_col

Time column index or name.

period

Seasonal period: "month", "day", or "hour".

method

Decomposition method: "additive" or "multiplicative".

verbose

Logical; if TRUE, prints progress message.

Value

A data frame with the residual component.

Examples

decompose_ts(data[1:500, c(1, 4, 17:19)], cols = 3:5, date_col = 1, period = "month")

dataprep documentation built on Oct. 1, 2026, 5:07 p.m.