
Derive a coarser calendar by truncating the hierarchy at a timeframe
Source:R/base-calendar.R
prune_calendar.RdAggregates a calendar to one of its own timeframes: leaves are
grouped by their member at timeframe, and the parts of the year they
stand for (total) are summed. The members of timeframe become the
leaf timeslices of the result. A merged timeslice is its own unit: its
share is the part of the year it stands for, with width 1 and
weight 1 (a month of m12_h24 is 31 days long, once). Where the
timeframe has a declared unit (see Calendar) the share is that unit,
the width the length of one cycle of the merged timeslices in units and
the weight the number of times it repeats. A member whose timeslices are
all left out (weight 0) keeps weight 0; timeslices left out take no part
in the sums.
timeframe = "ANNUAL" returns the implicit
whole-year root — a one-timeslice calendar (the root is named ANNUAL, never
YEAR, which is reserved for the Gregorian-year axis).
Arguments
- x
A
Calendar.- timeframe
One of
calendar's timeframes, or"ANNUAL"for the whole-year root.
Value
A Calendar whose hierarchy stops at timeframe. A coarser
timeframe that timeframe does not nest in (a cross-cutting grouping)
is dropped.
Details
Together with recast_calendar()'s acceptance of a timeframe name for
target=, this covers within-calendar aggregation (e.g. q4_h24 -> q4)
without constructing a second calendar by hand.
Examples
cal <- calendar_build("q4", "h24")
prune_calendar(cal, "QUARTER") # 4 timeslices, shares summed over hours
#> Calendar: q4_h24@QUARTER
#> Timeframes (1):
#> - QUARTER (4) [token: q4]
#> Leaf timeslices: 4
#> year_fraction: 1
#> year_start: month=1, day=1
#> utc_offset_minutes: 0
prune_calendar(cal, "ANNUAL") # 1 timeslice covering the year
#> Calendar: q4_h24@ANNUAL
#> Timeframes (1):
#> - ANNUAL (1)
#> Leaf timeslices: 1
#> year_fraction: 1
#> year_start: month=1, day=1
#> utc_offset_minutes: 0