skgrange / threadr

Tools to Thread Pieces Of Data Analysis Together
GNU General Public License v3.0
31 stars 7 forks source link

[Feature]: aggregate_by_date support same intervals as openair::timeaverage #10

Closed mooibroekd closed 1 month ago

mooibroekd commented 1 month ago

The aggregate_by_date function does currently not support interval = "2 week" notations. If this is applied, then the error message is:

Error in validate_rounding_nunit(.Call(C_parse_unit, as.character(unit))) : 
  Rounding with week > 1 is not supported. Use aseconds for arbitrary units.

I know that openair::timeAverage recalculates the avg.time variable to seconds, with approximation for month, season and year.

skgrange commented 1 month ago

The supported date intervals are provided by the lubridate package and multiple weeks are not supported because of potential ambiguity on what a user wants when considering multiple weeks. Would passing "14 days" to the function do what you want? For example:

# Valid two-weekly aggregation? 
aggregate_by_date(df, interval = "14 days")

If not, let me know and I can add a condition to push multiple weeks into seconds and use that as the interval. I hope this helps!