subtotal_dupe_removal {ReportSubtotal}R Documentation

Duplicate Subtotal Row Removal Function

Description

Removes duplicate subtotal rows, which may be created by totalling a variable with only one level. In tables with many variables, some may have only one level within one section and many in other sections.

Usage

subtotal_dupe_removal(
  data,
  column,
  iterator = 2,
  skip = 0,
  remove = "All",
  lead_name = "Lead_Column"
)

Arguments

data

Data frame or tibble to remove duplicate row labels from.

column

Column containing duplicate row labels.

iterator

Minimum number of rows meant to be between each section. Usually two.

skip

Number of rows to skip removing rows from. Usually zero. Can be used to dodge NA values.

remove

Label of subtotals to be removed. Usually "All".

lead_name

Default name for lead column used to filter duplicates.

Details

Adds a leading version of the requested column, which places each observation in the same row as the next observation. Usually the observation 2 rows on - determined by the iterator. From here if both the original and leading column equal the value to be removed, then the row is a duplicate subtotal and is removed. Note: the last few rows will have NA values in the leading column, so they are covered separately. Note: If you already have columns named Lead or Index, they receive a temporary suffix.

Value

The data report without duplicate subtotal rows.

Examples

library(dplyr)

group_by(mtcars, cyl, vs) %>% summarise(sum(wt), .groups = "keep") %>%
subtotal_row(mtcars, "wt") %>%
subtotal_dupe_removal(2)
group_by(mtcars, cyl, vs, am) %>% summarise(mean(hp), .groups = "keep") %>%
subtotal_row(mtcars, "hp", "mean") %>%
subtotal_dupe_removal(3, skip = 1)
group_by(mtcars, cyl, vs, am) %>% summarise(mean(hp), .groups = "keep") %>%
subtotal_row(mtcars, "hp", "mean") %>%
subtotal_dupe_removal(3, skip = 1)

[Package ReportSubtotal version 0.1.2 Index]