Closed mitchelloharawild closed 4 years ago
library(fpp3) B1 <- rnorm(12, mean = 5) + (1:12) B2 <- rnorm(12, mean = 5) M2 <- rnorm(12, mean = 25) ts_data <- tibble(value = c(B1, B2, M2), month = rep(yearmonth(paste("2020", 1:12, sep="-")), 3), B = agg_vec(c(rep("B1", 12), rep("B2", 12), rep(NA, 12)), c(rep(FALSE, 24), rep(TRUE, 12))), M = c(rep("M1", 24), rep("M2", 12))) %>% as_tsibble(key = c("B", "M"), index = month) ts_data %>% # Specify hierarchy aggregate_key(M / B, value = sum(value))
cc @GeorgeAthana
MRE:
tibble(A = fabletools:::agg_vec(letters)) %>% group_by(A = fabletools:::agg_vec(A))