mts_setTimeAxis {MazamaTimeSeries} | R Documentation |
Extend/contract mts time series to new start and end times
Description
Extends or contracts the time range of an mts object by adding/removing time steps at the start and end and filling any new time steps with missing values. The resulting time axis is guaranteed to be a regular, hourly axis with no gaps using the same timezone as the incoming mts object. This is useful when you want to place separate mts objects on the same time axis for plotting.
Dates can be anything that is understood by MazamaCoreUtils::parseDatetime()
including either of the following recommended formats:
"YYYYmmdd"
"YYYY-mm-dd"
Timezone determination precedence assumes that if you are passing in
POSIXct
values then you know what you are doing:
get timezone from
startdate
if it isPOSIXct
use passed in
timezone
get timezone from
mts
If either startdate
or enddate
is missing, the start or end of
the timeseries in mts
will be used.
If neither startdate
nor enddate
is a POSIXct
value
AND no timezone
is supplied, the timezone will be inferred from
the most common timezone found in mts
.
Usage
mts_setTimeAxis(mts = NULL, startdate = NULL, enddate = NULL, timezone = NULL)
Arguments
mts |
mts object. |
startdate |
Desired start date (ISO 8601). |
enddate |
Desired end date (ISO 8601). |
timezone |
Olson timezone used to interpret |
Value
The incoming mts time series object defined on a new time axis.
(A list with meta
and data
dataframes.)
Examples
library(MazamaTimeSeries)
# Default range
range(example_mts$data$datetime)
# One-sided extend with user specified timezone
example_mts %>%
mts_setTimeAxis(enddate = 20190815, timezone = "UTC") %>%
mts_extractData() %>%
dplyr::pull(datetime) %>%
range()
# Two-sided extend with user specified timezone
example_mts %>%
mts_setTimeAxis(20190615, 20190815, timezone = "UTC") %>%
mts_extractData() %>%
dplyr::pull(datetime) %>%
range()
# Two-sided extend without timezone (uses timezone from mts$meta$timezone)
example_mts %>%
mts_setTimeAxis(20190615, 20190815) %>%
mts_extractData() %>%
dplyr::pull(datetime) %>%
range()