Skip to contents

Clip, shift and re-interval a time series

Usage

ts_clip(ts, start, end)

ts_shift(ts, by = c("day", "month", "year", "start"), amount = 0, start = NULL)

ts_convert_interval(ts, to, average = TRUE)

Arguments

ts

a corehydro_ts.

start, end

the new bounds, for ts_clip().

by

"day", "month", "year" or "start".

amount

the number of days, months or years to shift by.

to

the target interval, one of ts_interval_names().

average

average across each block (the default) rather than summing.

Value

a corehydro_ts.

Details

ts_clip() keeps the ordinates inside [start, end]; both bounds must lie inside the series' own span. ts_shift() moves every date by a whole number of days, months or years, or – with by = "start" – re-anchors the series at a new start date and re-walks the rest at its interval (on an "irregular" series only the first ordinate moves, since there is no interval to walk). ts_convert_interval() resamples to another interval, interpolating to a finer one and block-averaging (or block-summing, with average = FALSE) to a coarser one; month, quarter, year and irregular intervals have no fixed number of hours, so converting to or from one raises.

Examples

ts <- time_series(as.Date("2000-01-01") + 0:9, 1:10)
ts_clip(ts, as.Date("2000-01-03"), as.Date("2000-01-06"))
#> <corehydro_ts> 4 ordinates, interval "one_day"
#>   2000-01-03 to 2000-01-06
#>   2000-01-03  3
#>   2000-01-04  4
#>   2000-01-05  5
#>   2000-01-06  6