Skip to content

FR : a clean generic aggregation method  #268

Open
@arnaud-feldmann

Description

@arnaud-feldmann

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions