Skip to contents

The library's in-place value transformations, exposed as pure verbs: each returns a new series rather than modifying ts.

Usage

ts_transform(ts, fun, constant = 0, power = 1, base = 10, indexes = NULL)

Arguments

ts

a corehydro_ts.

fun

one of "add", "subtract", "multiply", "divide", "absolute_value", "exponentiate", "logarithm", "inverse".

constant

the operand for add / subtract / multiply / divide.

power

the exponent for "exponentiate". Default 1.

base

the logarithm base. Default 10.

indexes

optional 1-BASED ordinate positions to restrict the transformation to (Python's transform() takes 0-based positions).

Value

a corehydro_ts.

Details

Every transformation LEAVES A MISSING VALUE MISSING except two, which follow the library: "logarithm" writes a missing value for any non-positive input, and ts_standardize() propagates missing values through the subtraction.

indexes restricts the transformation to the given 1-based ordinate positions. Two transformations behave differently from their siblings when an index is out of range, because the library does: "logarithm" and "inverse" raise, while the others skip it.

Examples

ts <- time_series(as.Date("2000-01-01") + 0:4, c(3, 1, 4, 1, 5))
ts_transform(ts, "multiply", constant = 10)
#> <corehydro_ts> 5 ordinates, interval "one_day"
#>   2000-01-01 to 2000-01-05
#>   2000-01-01  30
#>   2000-01-02  10
#>   2000-01-03  40
#>   2000-01-04  10
#>   2000-01-05  50