Learn R Programming

timeSeries (version 4041.111)

diff: Difference a 'timeSeries' object

Description

Difference a "timeSeries" object.

Usage

# S3 method for timeSeries
diff(x, lag = 1, diff = 1, trim = FALSE, pad = NA, ...)

Value

the differenced "timeSeries" object

Arguments

x

an object of class "timeSeries".

lag

an integer indicating which lag to use.

diff

an integer indicating the order of the difference.

trim

a logical flag. Should NAs at the beginning of the series be removed?

pad

a numeric value with which NAs should be replaced at the beginning of the series.

...

currently not used.

See Also

diff for base::diff, lag

Examples

Run this code
## load Microsoft dataset
x <- MSFT[1:12, ]
x

## compute differences
diff(x)   
   
## trimmed differences
diff(x, trim = TRUE) 

## padded differences
diff(x, trim = FALSE, pad = 0) 

Run the code above in your browser using DataLab