-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmts_setTimeAxis.Rd
81 lines (67 loc) · 2.51 KB
/
mts_setTimeAxis.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mts_setTimeAxis.R
\name{mts_setTimeAxis}
\alias{mts_setTimeAxis}
\title{Extend/contract \emph{mts} time series to new start and end times}
\usage{
mts_setTimeAxis(mts = NULL, startdate = NULL, enddate = NULL, timezone = NULL)
}
\arguments{
\item{mts}{\emph{mts} object.}
\item{startdate}{Desired start date (ISO 8601).}
\item{enddate}{Desired end date (ISO 8601).}
\item{timezone}{Olson timezone used to interpret \code{startdate} and \code{enddate}.}
}
\value{
The incoming \emph{mts} time series object defined on a new time axis.
(A list with \code{meta} and \code{data} dataframes.)
}
\description{
Extends or contracts the time range of an \emph{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
\emph{mts} object. This is useful when you want to place separate \emph{mts}
objects on the same time axis for plotting.
Dates can be anything that is understood by \code{MazamaCoreUtils::parseDatetime()}
including either of the following recommended formats:
\itemize{
\item{\code{"YYYYmmdd"}}
\item{\code{"YYYY-mm-dd"}}
}
Timezone determination precedence assumes that if you are passing in
\code{POSIXct} values then you know what you are doing:
\enumerate{
\item{get timezone from \code{startdate} if it is \code{POSIXct}}
\item{use passed in \code{timezone}}
\item{get timezone from \code{mts}}
}
If either \code{startdate} or \code{enddate} is missing, the start or end of
the timeseries in \code{mts} will be used.
If neither \code{startdate} nor \code{enddate} is a \code{POSIXct} value
AND no \code{timezone} is supplied, the timezone will be inferred from
the most common timezone found in \code{mts}.
}
\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()
}