Skip to contents

Prepare variable to be summarized

Usage

hts_prep_byvar(
  summarize_by = NULL,
  variables_dt = variable_list,
  hts_data,
  byvar_ids = c("hh_id", "person_id", "day_id", "trip_id", "vehicle_id"),
  byvar_wts = c("hh_weight", "person_weight", "day_weight", "trip_weight", "hh_weight"),
  ...
)

Arguments

summarize_by

Name of the variable to be prepped. Default is NULL.

variables_dt

List of variable locations and descriptions in data.table format.

hts_data

List containing household, person, day, trip, and vehicle datasets in data.table format.

byvar_ids

unique identifiers for each table in hts_data

byvar_wts

weight column for each table in hts_data

...

Additional parameters to pass to link{hts_melt_vars}

Value

Data table containing the variable to be summarized and other key columns.

Examples


hts_prep_byvar(
  summarize_by = "age",
  variables_dt = variable_list,
  hts_data = list(
    "hh" = hh,
    "person" = person,
    "day" = day,
    "trip" = trip,
    "vehicle" = vehicle
  )
)
#>       hh_id person_id person_weight age
#>    1:   356         1           229  10
#>    2:   724         2           128  11
#>    3:   681         3           888   7
#>    4:   114         4           350   2
#>    5:   165         5           825  10
#>   ---                                  
#> 2043:   931      2043           116   7
#> 2044:   667      2044           122   1
#> 2045:   543      2045           494   3
#> 2046:   749      2046           874  11
#> 2047:   364      2047           393  11
hts_prep_byvar(
  summarize_by = "race",
  variables_dt = variable_list,
  hts_data = list(
    "hh" = hh,
    "person" = person,
    "day" = day,
    "trip" = trip,
    "vehicle" = vehicle
  )
)
#>       person_id hh_id                 race
#>    1:         2   724          Two or more
#>    2:         8   365          Two or more
#>    3:        12   921          Two or more
#>    4:        13    28          Two or more
#>    5:        16   368          Two or more
#>   ---                                     
#> 2022:      2042   461 Prefer not to answer
#> 2023:      2044   667 Prefer not to answer
#> 2024:      2045   543 Prefer not to answer
#> 2025:      2046   749 Prefer not to answer
#> 2026:      2047   364 Prefer not to answer