trace_to_wide_factors: Reshape rating trace to wide step-value columns

View source: R/trace_helpers.R

trace_to_wide_factorsR Documentation

Reshape rating trace to wide step-value columns

Description

Convert normalized trace rows into one row per unique combination of identifying columns, with a separate column for each rating step. Generated step columns contain the trace's applied_value.

Usage

trace_to_wide_factors(
  term_trace,
  id_cols = c("row_number", "record_id", "coverage")
)

Arguments

term_trace

A data frame containing normalized rating trace rows, typically from rate_policies_with_trace().

id_cols

A character vector naming columns in term_trace that define the output rows. Names not present in term_trace are ignored.

Value

If term_trace is nonempty, a data frame with one row per unique combination of the available id_cols and columns named ⁠step_<number>_<term>⁠ containing applied step values. If term_trace is empty, the empty input data frame is returned unchanged.

Examples

ex <- example_rating_plan()

result <- rate_policies_with_trace(
  ex$policies,
  ex$plan
)

trace_to_wide_factors(
  result$term_trace
)

ratingtables documentation built on Sept. 6, 2026, 1:06 a.m.