-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmts_combine.Rd
89 lines (74 loc) · 2.84 KB
/
mts_combine.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
82
83
84
85
86
87
88
89
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/mts_combine.R
\name{mts_combine}
\alias{mts_combine}
\title{Combine multiple \emph{mts} time series objects}
\usage{
mts_combine(
...,
replaceMeta = FALSE,
overlapStrategy = c("replace all", "replace na")
)
}
\arguments{
\item{...}{Any number of valid \emph{mts} objects.}
\item{replaceMeta}{Logical specifying whether to allow replacement of
metadata associated with \code{deviceDeploymentIDs}.}
\item{overlapStrategy}{Strategy to use when data found in time series
overlaps.}
}
\value{
An \emph{mts} time series object containing all time series found
in the incoming \code{mts} objects.
(A list with \code{meta} and \code{data} dataframes.)
}
\description{
Create a combined \emph{mts} from any number of \emph{mts}
objects or from a list of \emph{mts} objects. The resulting \emph{mts}
object with contain all \code{deviceDeploymentIDs} found in any incoming
\emph{mts} and will have a regular time axis covering the the entire range
of incoming data.
If incoming time ranges are non-contiguous, the resulting \emph{mts} will
have gaps filled with \code{NA} values.
An error is generated if the incoming \emph{mts} objects have
non-identical metadata for the same \code{deviceDeploymentID} unless
\code{replaceMeta = TRUE}.
}
\note{
Data for any \code{deviceDeploymentIDs} shared among \emph{mts}
objects are combined with a "later is better" sensibility where any
data overlaps exist. To handle this, incoming \emph{mts} objects are first
split into "shared" and "unshared" parts.
Any "shared" parts are ordered based on the
time stamp of their last record. Then \code{dplyr::distinct()} is used to
remove records with duplicate \code{datetime} fields.
With \code{overlapStrategy = "replace all"}, any data records found
in "later" \emph{mts} objects are preferentially retained before the "shared"
data are finally reordered by ascending \code{datetime}.
With \code{overlapStrategy = "replace missing"}, only missing values in "earlier"
\emph{mts} objects are replaced with data records from "later" time series.
The final step is combining the "shared" and "unshared" parts and placing
them on a uniform time axis.
}
\examples{
library(MazamaTimeSeries)
ids1 <- example_mts$meta$deviceDeploymentID[1:5]
ids2 <- example_mts$meta$deviceDeploymentID[4:6]
ids3 <- example_mts$meta$deviceDeploymentID[8:10]
mts1 <-
example_mts \%>\%
mts_filterMeta(deviceDeploymentID \%in\% ids1) \%>\%
mts_filterDate(20190701, 20190703)
mts2 <-
example_mts \%>\%
mts_filterMeta(deviceDeploymentID \%in\% ids2) \%>\%
mts_filterDate(20190704, 20190706)
mts3 <-
example_mts \%>\%
mts_filterMeta(deviceDeploymentID \%in\% ids3) \%>\%
mts_filterDate(20190705, 20190708)
mts <- mts_combine(mts1, mts2, mts3)
# Should have 1:6 + 8:10 = 9 meta records and the full date range
nrow(mts$meta)
range(mts$data$datetime)
}