Learn R Programming

oce (version 0.2-1)

detrend: Detrend a set of observations

Description

Detrend a set of observations

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 new vector that is is zero at the start and end.

Details

Detrends y by subtracting a linear trend in x, to make 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}.

Examples

Run this code
x <- seq(0, 0.9 * pi, length.out=50)
y <- sin(x)
plot(x, y)
lines(x, detrend(y), col='gray')
abline(h=0, lty='dotted')

Run the code above in your browser using DataLab