ts_: Constructing ts-Functions

Description Usage Arguments Details Value See Also Examples

View source: R/ts_.R

Description

ts_ turns an existing function into a function that can deal with ts-boxable time series objects.

Usage

1
2
3
4
5
load_suggested(pkg)

ts_(fun, class = "ts", vectorize = FALSE, reclass = TRUE)

ts_apply(x, fun, ...)

Arguments

pkg

external package, to be suggested (automatically added by ts_) predict(). (See examples)

fun

function, to be made available to all time series classes

class

class that the function uses as its first argument

vectorize

should the function be vectorized? (not yet implemented)

reclass

logical, should the new function return the same same ts-boxable output as imputed?

x

ts-boxable time series, an object of class ts, xts, zoo, data.frame, data.table, tbl, tbl_ts, tbl_time, or timeSeries.

...

arguments passed to subfunction

Details

The ts_ function is a constructor function for tsbox time series functions. It can be used to wrap any function that works with time series. The default is set to R base "ts" class. ts_ deals with the conversion stuff, 'vectorizes' the function so that it can be used with multiple time series.

Value

A function that accepts ts-boxable time series as an input.

See Also

ts_examples, for a few useful examples of functions generated by ts_.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ts_(rowSums)(ts_c(mdeaths, fdeaths))
ts_plot(mean = ts_(rowMeans)(ts_c(mdeaths, fdeaths)), mdeaths, fdeaths)
ts_(function(x) predict(prcomp(x)))(ts_c(mdeaths, fdeaths))
ts_(function(x) predict(prcomp(x, scale = TRUE)))(ts_c(mdeaths, fdeaths))
ts_(dygraphs::dygraph, class = "xts")

# attach series to serach path
ts_attach <- ts_(attach, class = "tslist", reclass = FALSE)
ts_attach(EuStockMarkets)
ts_plot(DAX, SMI)
detach()

christophsax/tsbox documentation built on June 26, 2018, 1:13 p.m.