| detrend_ts | R Documentation |
Fits a linear trend (intercept + slope) to each selected numeric column (or vector) and returns the residuals. This is useful for removing long-term trends before correlation analysis.
detrend_ts(data, cols = NULL, date_col = NULL, verbose = FALSE)
data |
A data frame, matrix, or numeric vector. |
cols |
Column indices or names to detrend. If NULL, all numeric columns are used. |
date_col |
Optional time column (not strictly required for linear detrending). |
verbose |
Logical; if |
A data frame or vector with the linear trend removed.
detrend_ts(data[1:100, c(1, 4, 17:19)], cols = 3:5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.