I am trying to merge()
two tsibble
objects that contain aggregated values.
The reason I cannot use cbind()
is because one of the aggregated tsibble
objects contains values only for the "parent" level (i.e., upper-level) of the hierarchy, not the "child" level (to use the language from the aggregated_key()
page on https://fabletools.tidyverts.org/reference/aggregate_key.html). In other words, one of the data sets has one fewer columns than the other.
A generalizable segment of code for the process I wish to perform is:
Agg_TS_1 \<- as_tsibble(NonAgg_TS_1, index = Date, key = c("Parent", "Child")) %>% aggregate_key(Parent/Child, Value_1 = sum(Value1))
Agg_TS_2 \<- as_tsibble(NonAgg_TS_2, index = Date, key = "Parent") %>% aggregate_key(Parent, Value2 = sum(Value2))
merge(Agg_TS_1, Agg_TS_2, by = c("Date", "Parent"))
However, the merge()
function seems to not take aggregated values, as I get the error Error in `stop_vctrs()`: ! `levels.agg_vec()` not supported. Run `rlang::last_error()` to see where the error occurred.
each time I try to merge these.
Were this a data.frame or some other matrix containing no aggregation structure, merge()
would simply propagate Value 2
in the rows with that in which it is missing due to Agg_TS_2
having no Child
level in the hierarchy. However, I get the above-stated error.
Thoughts on how to remedy this?