Skip to contents

Three whole-series transformations, each returning a new series.

Usage

ts_cumulative_sum(ts)

ts_difference(ts, lag = 1, differences = 1)

ts_standardize(ts)

Arguments

ts

a corehydro_ts.

lag

the gap between the elements being subtracted. Default 1.

differences

how many times to difference. Default 1.

Value

a corehydro_ts.

Details

ts_cumulative_sum() treats a missing value as zero while accumulating but keeps its ordinate, and – following the library – the result carries the DEFAULT "one_day" interval rather than the source's. ts_difference() keeps the source's start date rather than shifting forward by the lag. ts_standardize() subtracts the mean and divides by the standard deviation, both computed over the observed values, and errors when the spread is zero.

Examples

ts <- time_series(as.Date("2000-01-01") + 0:5, c(3, 1, 4, 1, 5, 9))
ts_difference(ts)
#> <corehydro_ts> 5 ordinates, interval "one_day"
#>   2000-01-01 to 2000-01-05
#>   2000-01-01  -2
#>   2000-01-02  3
#>   2000-01-03  -3
#>   2000-01-04  4
#>   2000-01-05  4