You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am joining multiple time series values collected on different intervals, ranging from months to years. Consequently, I need to harmonize the intervals to perform the join.
At the moment, I don't see a documented method for setting the desired interval, either directly, or when calling fill_gaps.
StackOverflow shows a mechanism for overriding the interval by explicitly changing the object attribute (see https://stackoverflow.com/a/75981369), but I prefer to use documented interfaces whenever possible.
For my current code, it would be very helpful to have an additional optional .interval argument to fill_gaps that performs this step.
> library(tidyverse)
>df1<- tsibble(quarter= yearquarter(as_date(c('2020-1-1','2021-1-1','2022-3-1'))),
+amount= c(5, 2, 1))
Using`quarter`asindexvariable.>df2<- tsibble(quarter= yearquarter(as_date(c('2022-1-1','2022-4-1','2022-7-1'))),
+amount= c(5, 2, 1))
Using`quarter`asindexvariable.>###># Existing functionality>###>> interval(df1)
<interval[1]>
[1] 4Q># --> Fills 4Q interval>df1 %>% fill_gaps(.start=yearquarter('2020-01-01'), .end=yearquarter('2023-01-01'))
# A tsibble: 4 x 2 [4Q]quarteramount<qtr><dbl>12020Q1522021Q1232022Q1142023Q1NA># --> Fills 1Q interval> interval(df2)
<interval[1]>
[1] 1Q>df2 %>% fill_gaps(.start=yearquarter('2020-01-01'), .end=yearquarter('2023-01-01'))
# A tsibble: 13 x 2 [1Q]quarteramount<qtr><dbl>12020Q1NA22020Q2NA32020Q3NA42020Q4NA52021Q1NA62021Q2NA72021Q3NA82021Q4NA92022Q15102022Q22112022Q31122022Q4NA132023Q1NA>###># Desired functionality: Fill to individual quarter >##>df1 %>% fill_gaps_interval(.start=yearquarter('2020-01-01'), .end=yearquarter('202 .... [TRUNCATED] # A tsibble: 13 x 2 [1Q] quarter amount <qtr> <dbl> 1 2020 Q1 5 2 2020 Q2 NA 3 2020 Q3 NA 4 2020 Q4 NA 5 2021 Q1 2 6 2021 Q2 NA 7 2021 Q3 NA 8 2021 Q4 NA 9 2022 Q1 110 2022 Q2 NA11 2022 Q3 NA12 2022 Q4 NA13 2023 Q1 NA> df2 %>% fill_gaps_interval(.start=yearquarter('2020-01-01'), .end=yearquarter('2023-01-01'), .interval=c(quarter=1))# A tsibble: 13 x 2 [1Q] quarter amount <qtr> <dbl> 1 2020 Q1 NA 2 2020 Q2 NA 3 2020 Q3 NA 4 2020 Q4 NA 5 2021 Q1 NA 6 2021 Q2 NA 7 2021 Q3 NA 8 2021 Q4 NA 9 2022 Q1 510 2022 Q2 211 2022 Q3 112 2022 Q4 NA13 2023 Q1 NA
The text was updated successfully, but these errors were encountered:
warnes
changed the title
FR: Provide optional argument to fill_gaps to specify desired interval.
FR: Provide optional argument to tsibble::fill_gaps to specify desired interval.
Sep 28, 2023
I am joining multiple time series values collected on different intervals, ranging from months to years. Consequently, I need to harmonize the intervals to perform the join.
At the moment, I don't see a documented method for setting the desired interval, either directly, or when calling
fill_gaps
.StackOverflow shows a mechanism for overriding the
interval
by explicitly changing the object attribute (see https://stackoverflow.com/a/75981369), but I prefer to use documented interfaces whenever possible.For my current code, it would be very helpful to have an additional optional
.interval
argument tofill_gaps
that performs this step.Perhaps something like these:
Reproducable Example:
The text was updated successfully, but these errors were encountered: