Tabulate target variable by method
run_tabulate_method.RdTabulates a target variable using the specified method, supporting custom preparation, direct tabulation, or pass-through. Use to generate summary tables for targets, with optional weighting and method selection.
Usage
run_tabulate_method(
method,
target_name,
h_data,
p_data,
codebook,
weight = FALSE,
settings
)Arguments
- method
character(1). Name of method to use. Must match a function in
get_target_methods(), or be "tabulate" or "pass_through".- target_name
character(1). Name of target variable to tabulate. Must match column in input data.
- h_data
data.table. Household-level input. Required columns:
For person-level targets: must include
SERIALNO,PWGTPif weighted.For household-level targets: must include
SERIALNO,WGTPif weighted. Rows: one per household. Modified by reference: no (returns copy).
- p_data
data.table. Person-level input. Required columns:
For person-level targets: must include
person_id, target column.For household-level targets: not required. Rows: one per person. Modified by reference: no (returns copy).
- codebook
data.table. Codebook for variable mapping (passed to target prep functions).
- weight
logical(1). If TRUE, tabulates weighted counts using PUMS weights if available.
- settings
list. Project settings; must include target configs and method definitions.
Value
data.table. Tabulated summary of target variable.
Columns: ID column (
person_idorhh_id), target variable, and optionally weighted counts.Row order: by ID and target value.
Details
Selects ID column using regex
^p_for person-level targets, else household-level.If PUMS and
weight = TRUE, selects weight column using regex^p_forPWGTP, elseWGTP.If
methodmatches a function inget_target_methods(), calls that function to prepare the target variable, then tabulates usingtabulate_target().If
method == "tabulate", tabulates directly from input data.If
method == "pass_through", returns input data columns for ID and target only.Error handling: stops if method is invalid or not implemented.
Uses
%like%for regex matching of target names and method selection.
Settings
Uses all target configs in
settings$targetsand method definitions fromget_target_methods().
See also
tabulate_target, get_target_methods, prepare_targets
Other target preparation:
get_target_methods(),
prep_target_adults(),
prep_target_age(),
prep_target_commutemode(),
prep_target_cross(),
prep_target_edulevel(),
prep_target_employment(),
prep_target_ethnicity(),
prep_target_gender(),
prep_target_h_size(),
prep_target_income(),
prep_target_kids(),
prep_target_race(),
prep_target_univstudent(),
prep_target_vehicles(),
prep_target_workers(),
prep_transit_target(),
prepare_targets()
Examples
## Not run:
run_tabulate_method("prep_target_gender", "p_gender", h_data, p_data, codebook, weight = TRUE, settings)
#> Error: object 'h_data' not found
run_tabulate_method("tabulate", "h_income", h_data, p_data, codebook, weight = FALSE, settings)
#> Error: object 'h_data' not found
## End(Not run)