Learn R Programming

dataprep (version 0.1.8)

decompose_ts: 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)

Value

A data frame with the residual component.

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.

Examples

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

Run the code above in your browser using DataLab