Learn R Programming

oce (version 0.9-19)

detrend: Detrend a set of observations

Description

Detrends y by subtracting a linear trend in x, to create Y that has Y[1]=0 and Y[length(Y)]=0. If y is not given, then y is taken from x, and x is set to the series of integers from 1 to length{x}.

Usage

detrend(x, y)

Arguments

x
a vector of numerical values. If y is not given, then x is taken for y.
y
an optional vector

Value

A list containing Y, the detrended version of y, and the intercept a and slope b of the linear function of x that is subtracted from y to yield Y.

Examples

Run this code

x <- seq(0, 0.9 * pi, length.out=50)
y <- sin(x)
plot(x, y)
d <- detrend(x, y)
points(x, d$Y, pch=20)
abline(h=0, lty='dotted')
abline(d$a, d$b, col='red')
points(x, d$Y + d$a + d$b * x, col='blue', pch='+')

Run the code above in your browser using DataLab