library(tsibble)
library(dplyr)
example <- as_tsibble(ts(rep(1,10),frequency = 12,start=2010))
example %>%
index_by(quarter = ~ yearquarter(.)) %>%
summarize(value=sum(value))
# A tsibble: 4 x 2 [1Q]
# quarter value
# <qtr> <dbl>
#1 2010 Q1 3
#2 2010 Q2 3
#3 2010 Q3 3
#4 2010 Q4 1
Here the 1 is unwanted, as sum
isn't set to na.rm=TRUE
. I'd like a readable way, relying on tsibbles only (ie without any time filtering on the high frequency index, nor adding manual month observations), to make strict aggregations on tsibble. Ie to ensure the uncomplete low-frequencies values are NA. There, the strict approach would be 2010 Q4 to be NA, not 1.
There appears not to be any fill_gaps
argument within the package tsibble
that force the filling to go until the end of the lower frequency, that would allow something like
example %>%
index_by(quarter = ~ yearquarter(.)) %>%
fill_gaps() %>%
summarize(value=sum(value))
to give the right strict aggregation involving a NA.