Skip to contents

Add vehicle_id to trip table

Usage

hts_trip_vehid(
  trip_table,
  vehicle_table,
  vehicle_mode_type = "Vehicle",
  values_dt = value_labels,
  ...
)

Arguments

trip_table

Dataset of trips in data.table format.

vehicle_table

Dataset of vehicles in data.table format.

vehicle_mode_type

Mode type label for vehicle. Default is 'Vehicle'.

values_dt

Dataset of value labels in data.table format.

...

Additional arguments passed to link{factorize_column}

Value

Trip table with vehicle_id attached.

Examples


require(data.table)
trip_ex = data.table(
  hh_id = sample(1:10, size = 30, replace = TRUE),
  trip_id = 1:30,
  mode_type = sample(1:2, size = 30, replace = TRUE),
  mode_1 = sample(1, size = 30, replace = TRUE)
)
vehicle_ex = data.table(
  hh_id = sample(1:10, size = 30, replace = TRUE),
  vehicle_id = 1:30
)
values_ex = data.table(
  variable = c(rep("mode_type", 2), ("mode_1")),
  value = c(1, 2, 1),
  value_label = c("Vehicle", "Walk", "Car")
)
hts_trip_vehid(
  trip_table = trip_ex,
  vehicle_table = vehicle_ex,
  vehicle_mode_type = "Vehicle",
  values_dt = values_ex
)
#>     hh_id trip_id mode_type mode_1 vehicle_id
#>  1:     3       1         2      1       <NA>
#>  2:     7       2         1      1       <NA>
#>  3:     3       3         1      1       <NA>
#>  4:     8       4         2      1       <NA>
#>  5:     7       5         2      1       <NA>
#>  6:     8       6         2      1       <NA>
#>  7:     2       7         2      1       <NA>
#>  8:     8       8         2      1       <NA>
#>  9:     6       9         1      1       <NA>
#> 10:     5      10         2      1       <NA>
#> 11:    10      11         1      1       <NA>
#> 12:     5      12         1      1       <NA>
#> 13:     1      13         2      1       <NA>
#> 14:     8      14         1      1       <NA>
#> 15:     6      15         2      1       <NA>
#> 16:     4      16         1      1       <NA>
#> 17:     9      17         2      1       <NA>
#> 18:    10      18         2      1       <NA>
#> 19:     7      19         1      1       <NA>
#> 20:     7      20         1      1       <NA>
#> 21:     9      21         1      1       <NA>
#> 22:     2      22         2      1       <NA>
#> 23:     8      23         2      1       <NA>
#> 24:     7      24         1      1       <NA>
#> 25:     4      25         2      1       <NA>
#> 26:     6      26         2      1       <NA>
#> 27:     1      27         1      1       <NA>
#> 28:     6      28         1      1       <NA>
#> 29:     8      29         2      1       <NA>
#> 30:    10      30         2      1       <NA>
#>     hh_id trip_id mode_type mode_1 vehicle_id