View source: R/methods-epi_archive.R
epix_merge | R Documentation |
epi_archive
objectsMerges two epi_archive
s that share a common geo_value
, time_value
, and
set of key columns. When they also share a common versions_end
, using
epix_as_of
on the result should be the same as using epix_as_of
on x
and y
individually, then performing a full join of the DT
s on the
non-version key columns (potentially consolidating multiple warnings about
clobberable versions). If the versions_end
values differ, the sync
parameter controls what is done.
epix_merge(
x,
y,
sync = c("forbid", "na", "locf", "truncate"),
compactify = TRUE
)
x , y |
Two |
sync |
Optional; character. The argument that decides how to handle the situation when one signal has a more recent revision than another signal for a key that they have both already observed. The options are:
|
compactify |
Optional; |
When merging archives, unless the archives have identical data release patterns, we often have to handle the situation when one signal has a more recent observation for a key than another signal. In this case, we have two options:
if the the other signal has never observed that key, we need to introduce
NA
s in the non-key variables for the missing signal,
if the other signal has observed that key previously, but at an ealier
revision date, then we need to decide how to handle the missing value in the
more recent signal; the sync
argument controls this behavior.
In all cases, clobberable_versions_start
will be set to the
earliest version that could be clobbered in either input archive.
the resulting epi_archive
# Example 1
# The s1 signal at August 1st gets revised from 10 to 11 on August 2nd
s1 <- tibble::tibble(
geo_value = c("ca", "ca", "ca"),
time_value = as.Date(c("2024-08-01", "2024-08-01", "2024-08-02")),
version = as.Date(c("2024-08-01", "2024-08-02", "2024-08-02")),
signal1 = c(10, 11, 7)
)
s2 <- tibble::tibble(
geo_value = c("ca", "ca"),
time_value = as.Date(c("2024-08-01", "2024-08-02")),
version = as.Date(c("2024-08-03", "2024-08-03")),
signal2 = c(2, 3)
)
s1 <- s1 %>% as_epi_archive()
s2 <- s2 %>% as_epi_archive()
merged <- epix_merge(s1, s2, sync = "locf")
merged[["DT"]]
# Example 2
# The s1 signal at August 1st gets revised from 12 to 13 on August 3rd
s1 <- tibble::tibble(
geo_value = c("ca", "ca", "ca", "ca"),
time_value = as.Date(c("2024-08-01", "2024-08-01", "2024-08-02", "2024-08-03")),
version = as.Date(c("2024-08-01", "2024-08-03", "2024-08-03", "2024-08-03")),
signal1 = c(12, 13, 22, 19)
)
s2 <- tibble::tibble(
geo_value = c("ca", "ca"),
time_value = as.Date(c("2024-08-01", "2024-08-02")),
version = as.Date(c("2024-08-02", "2024-08-02")),
signal2 = c(4, 5),
)
s1 <- s1 %>% as_epi_archive()
s2 <- s2 %>% as_epi_archive()
merged <- epix_merge(s1, s2, sync = "locf")
merged[["DT"]]
# Example 3:
s1 <- tibble::tibble(
geo_value = c("ca", "ca", "ca"),
time_value = as.Date(c("2024-08-01", "2024-08-02", "2024-08-03")),
version = as.Date(c("2024-08-01", "2024-08-02", "2024-08-03")),
signal1 = c(14, 11, 9)
)
# The s2 signal at August 1st gets revised from 3 to 5 on August 3rd
s2 <- tibble::tibble(
geo_value = c("ca", "ca", "ca"),
time_value = as.Date(c("2024-08-01", "2024-08-01", "2024-08-02")),
version = as.Date(c("2024-08-02", "2024-08-03", "2024-08-03")),
signal2 = c(3, 5, 2),
)
s1 <- s1 %>% as_epi_archive()
s2 <- s2 %>% as_epi_archive()
merged <- epix_merge(s1, s2, sync = "locf")
merged[["DT"]]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.