powered by
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)
A data frame or vector with the linear trend removed.
A data frame, matrix, or numeric vector.
Column indices or names to detrend. If NULL, all numeric columns are used.
Optional time column (not strictly required for linear detrending).
Logical; if TRUE, prints progress message.
TRUE
detrend_ts(data[1:100, c(1, 4, 17:19)], cols = 3:5)
Run the code above in your browser using DataLab