Summarize the number of occurrences of each category (in count_column
)
within each group (defined by group_column
). The result is returned
in a wide format, where each unique category becomes a column.
Missing combinations are filled with 0.
Examples
df <- data.frame(
Incurred_Date = as.Date(c('2021-01-01', '2021-01-01', '2021-01-02')),
Status = c("Open", "Closed", "Open")
)
get_counts_by_category(df,
group_column = Incurred_Date,
count_column = Status,
names_prefix = "Status_")
#> # A tibble: 2 × 3
#> Incurred_Date Status_Closed Status_Open
#> <date> <dbl> <dbl>
#> 1 2021-01-01 1 1
#> 2 2021-01-02 0 1