Skip to contents

Get frequency counts for a variable, applying interval bounds and wide-format aggregation. Use to summarize categorical or binned variables for reporting and weighting.

Usage

tabulate_target(
  dt,
  col,
  upper_bounds = NULL,
  prefix = col,
  id_col,
  weight_col = NULL,
  ignore_missing = FALSE
)

Arguments

dt

data.table. Persons or households table.

col

character(1). Column to tabulate (e.g., num_people).

upper_bounds

numeric vector. Interval bounds to create. Default NULL.

prefix

character(1). Prefix for new columns. Default: column name.

id_col

character(1). Column to aggregate across (e.g., hh_id).

weight_col

character(1). Weight column for aggregation. Default NULL (frequency count).

ignore_missing

logical. Ignore missing values in frequency count. Default FALSE.

Value

data.table. Wide-format frequency table by ID.

Details

  • Applies interval bounds using cut_and_label or factor conversion.

  • Aggregates counts by ID and weight columns; supports missing value handling.

  • Returns a wide-format data.table with frequency columns.

  • Assumes valid input schema; errors if missing columns.

Settings

None.

See also

  • cut_and_label

  • scripts/reporting/tabulate_target.R

Other reporting utilities: find_level_idx(), get_target_map(), summarize_data(), summarize_pums(), summarize_survey()

Examples

## Not run:
tabulate_target(dt, col = "num_people", upper_bounds = c(1, 2, 3), id_col = "hh_id")
#> Error in `:=`(wt, 1): Check that is.data.table(DT) == TRUE. Otherwise, :=, `:=`(...) and let(...) are defined for use in j, once only and in particular ways. Note that namespace-qualification like data.table::`:=`(...) is not supported. See help(":=").
## End(Not run)