Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR : a clean generic aggregation method #268

Open
arnaud-feldmann opened this issue Nov 2, 2021 · 0 comments
Open

FR : a clean generic aggregation method #268

arnaud-feldmann opened this issue Nov 2, 2021 · 0 comments

Comments

@arnaud-feldmann
Copy link

arnaud-feldmann commented Nov 2, 2021

Hi,
despite the adding of .start and .end for fill_gaps, there is still no clean way to aggregate.

I'd like something like that to work on compatible tsibbles :

agreg_tsibble <- function(x,f=sum,unit) {
  
  f <- match.fun(f)
  ind <- index(x)
  key <- key(x)
  
  dates_lims <- pull(x,as.character(ind)) %>%
  {c(min(.,na.rm = TRUE),max(.,na.rm=TRUE))} %>%
  as_date %>%
  {c(floor_date(.[1L],unit),ceiling_date(.[2L],unit,change_on_boundary = TRUE))}
  
  x %>% 
  fill_gaps(.start = dates_lims[1L],
            .end = dates_lims[2L]) %>% 
  index_by(quarter = ~ yearquarter(.)) %>%
  group_by_key() %>%
  summarize(across(! (!!ind),f))

}

There is some things that forbids that :

  • incompatibility between dates formats in .start and .end (cf my other issue Methods to compare year* with dates #267 )
  • ceiling_date isn't the right max limit, it should be something like ceiling_date(.[2L],unit,change_on_boundary = TRUE)-"hf interval" but I don't know how to substract tsibble objects of class interval

It would be a very great feature to add, because right now it's way more complicated to aggregate than in stats::ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant