Skip to contents

Bind a column from one table to another

Usage

hts_cbind_var(
  lhs_table,
  rhs_var,
  hts_data,
  variable_list = variable_list,
  return_weight_cols = FALSE,
  cbind_ids = c("hh_id", "person_id", "day_id", "trip_id", "vehicle_id"),
  cbind_wts = c("hh_weight", "person_weight", "day_weight", "trip_weight", "hh_weight")
)

Arguments

lhs_table

Table to bind a column to in data.table format

rhs_var

Variable to bind to the lhs_table.

hts_data

List of household, person, vehicle, day, and trip tables in data.table format.

variable_list

A variable list with descriptions and table locations of variables.

return_weight_cols

If true binds weight variable along with rhs_var to lhs_table. Default is FALSE.

cbind_ids

list of unique identifiers for each table in hts_data

cbind_wts

list of weight for each table in hts_data

Value

Inputted table with inputted variable binded.

Examples


require(data.table)
hts_cbind_var(
  lhs_table = trip,
  rhs_var = "speed_mph",
  hts_data = test_data,
  variable_list = variable_list
)
#> Joining speed_mph to table on day_id, trip_id, speed_mph, hh_id, person_id, trip_weight
#>        day_id trip_id  speed_mph hh_id person_id trip_weight distance_miles
#>     1:      1    6099  3.8030030   642       820         237     0.31691692
#>     2:      1    6848  0.3570582   642       820         957     0.07736261
#>     3:      1    9240  1.3936891   642       820         578     0.47308002
#>     4:      1   13883 10.7289440   642       820         361    10.72894403
#>     5:      1   15759  9.2827577   642       820         287     0.16244826
#>    ---                                                                     
#> 15870:   4125     719  1.5648402   876      1684         954     7.77203953
#> 15871:   4125    4397  8.5320851   876      1684         977     1.42201419
#> 15872:   4125    4505 16.3377147   876      1684         999     3.23577517
#> 15873:   4125    7897 42.9297111   876      1684         167    22.65734754
#> 15874:   4125   14260 10.5795319   876      1684         841     1.76325532
#>        mode_type mode_1 mode_2 num_travelers d_purpose_category travel_date
#>     1:         8     34    995             2                  7  2023-05-28
#>     2:         8      6    995             1                  7  2023-05-28
#>     3:         2      2    995             1                  1  2023-05-28
#>     4:        13      2     23             1                 11  2023-05-28
#>     5:         1      1    995             1                  9  2023-05-28
#>    ---                                                                     
#> 15870:         1      1    995             1                 12  2023-05-30
#> 15871:         8     34    995             2                  7  2023-05-30
#> 15872:         8      6    995             1                 12  2023-05-30
#> 15873:         8      6    995             1                  2  2023-05-30
#> 15874:         8      7    995             1                  2  2023-05-30
hts_cbind_var(
  lhs_table = trip,
  rhs_var = "speed_mph",
  hts_data = test_data,
  variable_list = variable_list,
  return_weight_cols = TRUE
)
#> Joining speed_mph to table on day_id, trip_id, speed_mph, hh_id, person_id, trip_weight
#>        day_id trip_id  speed_mph hh_id person_id trip_weight distance_miles
#>     1:      1    6099  3.8030030   642       820         237     0.31691692
#>     2:      1    6848  0.3570582   642       820         957     0.07736261
#>     3:      1    9240  1.3936891   642       820         578     0.47308002
#>     4:      1   13883 10.7289440   642       820         361    10.72894403
#>     5:      1   15759  9.2827577   642       820         287     0.16244826
#>    ---                                                                     
#> 15870:   4125     719  1.5648402   876      1684         954     7.77203953
#> 15871:   4125    4397  8.5320851   876      1684         977     1.42201419
#> 15872:   4125    4505 16.3377147   876      1684         999     3.23577517
#> 15873:   4125    7897 42.9297111   876      1684         167    22.65734754
#> 15874:   4125   14260 10.5795319   876      1684         841     1.76325532
#>        mode_type mode_1 mode_2 num_travelers d_purpose_category travel_date
#>     1:         8     34    995             2                  7  2023-05-28
#>     2:         8      6    995             1                  7  2023-05-28
#>     3:         2      2    995             1                  1  2023-05-28
#>     4:        13      2     23             1                 11  2023-05-28
#>     5:         1      1    995             1                  9  2023-05-28
#>    ---                                                                     
#> 15870:         1      1    995             1                 12  2023-05-30
#> 15871:         8     34    995             2                  7  2023-05-30
#> 15872:         8      6    995             1                 12  2023-05-30
#> 15873:         8      6    995             1                  2  2023-05-30
#> 15874:         8      7    995             1                  2  2023-05-30