Skip to contents

Rounds groups of columns to integers so their sum matches a total column, adjusting the largest value for any rounding difference. Use for preparing control totals for weighting.

Usage

integerize(data, grp_pattern, id_var, total_col = NULL)

Arguments

data

data.table. Input with columns to integerize.

grp_pattern

character(1). Regex pattern for columns to integerize.

id_var

character(1). ID column for row identification.

total_col

character(1), optional. Total column to match (default auto).

Value

data.table. Copy of input with integerized columns.

Details

  • Identifies columns by pattern and rounds values.

  • Adjusts largest column to match total exactly.

  • Returns data.table with integerized columns.

  • Assumes input is a data.table and columns are numeric.

Settings

None.

See also

integerize_probs

Other weighting utilities: integerize_probs()

Examples

## Not run:
integerize(dt, 'h_', 'hh_id', 'h_total')
#> Error in integerize(dt, "h_", "hh_id", "h_total"): could not find function "integerize"