Skip to contents

Filter datasets to only keep specified ids

Usage

hts_filter_data(hts_data, ids, id_name)

Arguments

hts_data

List of containing household travel data tables.

ids

List of ids to keep in all of the tables

id_name

Name of id being used for filtering (e.g., hh_id, person_id)

Value

Inputted list of tables filtered to the specified ids.

Examples


require(data.table)

data(test_data)

hts_filter_data(
  hts_data = test_data,
  ids = hh[num_people > 5, hh_id],
  id_name = "hh_id"
)
#> $hh
#>     hh_id sample_segment income_detailed income_followup  home_lon home_lat
#>  1:    28             13             999               1 -93.87387 35.32633
#>  2:   176             21               2             995 -89.80981 37.44244
#>  3:   194             18               6             995 -96.11612 36.69269
#>  4:   216             16               6             995 -86.66667 36.93093
#>  5:   243             16               9             995 -86.54655 37.57558
#>  6:   270             18               2             995 -90.09009 35.20721
#>  7:   277             17             999               3 -97.33734 35.52252
#>  8:   462             17               2             995 -82.76276 34.18418
#>  9:   562             10               7             995 -87.44745 36.51752
#> 10:   664             17               7             995 -98.81882 35.70470
#> 11:   724              9               3             995 -92.25225 38.58458
#> 12:   745             19               7             995 -98.13814 37.12012
#> 13:   820             16             999             999 -89.16917 34.84284
#> 14:   845             18               6             995 -99.37938 38.29029
#> 15:   981              2               7             995 -83.22322 34.74474
#>     home_county residence_type num_people num_trips hh_weight
#>  1:           2            997          6        37       522
#>  2:           1              4          6        35        90
#>  3:           2              4          6        28       591
#>  4:           2              4          6        43       972
#>  5:           1              1          6        35       523
#>  6:           1              4          6        48       355
#>  7:           3              4          6        56       486
#>  8:           1              4          6        47        15
#>  9:           1              1          6        44       154
#> 10:           3              1          6        43       524
#> 11:           2              4          6        31       664
#> 12:           2              1          9        86       678
#> 13:           1              1          6        40       107
#> 14:           1              4          7        66       498
#> 15:           1              4          6        45       414
#> 
#> $person
#>     person_id ethnicity_1 ethnicity_2 ethnicity_3 ethnicity_4 ethnicity_997
#>  1:         2           1           0           0           1             1
#>  2:        13           1           0           1           0             1
#>  3:        20           0           0           0           0             0
#>  4:        56           0           0           0           0             0
#>  5:        60           0           0           0           1             0
#>  6:       101           0           0           0           0             0
#>  7:       120           0           0           0           0             0
#>  8:       121           1           0           1           0             0
#>  9:       149           0           0           0           0             0
#> 10:       150           0           0           0           0             0
#> 11:       153           1           1           0           1             1
#> 12:       164           0           0           0           0             0
#> 13:       169           0           0           0           0             0
#> 14:       198           0           0           0           0             0
#> 15:       238           0           0           0           0             0
#> 16:       253           1           1           0           0             1
#> 17:       299           0           0           0           0             0
#> 18:       307           0           0           0           0             0
#> 19:       354           0           0           0           0             0
#> 20:       365           0           0           0           0             0
#> 21:       383           1           1           1           1             0
#> 22:       388           0           0           1           1             1
#> 23:       397           0           0           0           0             0
#> 24:       410           0           0           0           0             0
#> 25:       461           0           0           1           1             1
#> 26:       469           1           0           0           0             0
#> 27:       474           1           0           0           1             1
#> 28:       480           0           0           0           0             0
#> 29:       519           0           1           1           1             1
#> 30:       525           0           0           0           0             0
#> 31:       542           1           0           0           1             1
#> 32:       557           1           0           1           1             0
#> 33:       578           0           0           0           0             0
#> 34:       588           0           1           1           0             1
#> 35:       616           0           0           0           0             0
#> 36:       668           0           1           1           0             0
#> 37:       701           0           0           1           1             0
#> 38:       713           0           0           0           0             0
#> 39:       728           0           0           0           0             0
#> 40:       734           0           1           1           1             0
#> 41:       784           0           0           0           0             0
#> 42:       819           0           1           1           1             0
#> 43:       821           0           0           1           1             1
#> 44:       826           0           0           0           0             0
#> 45:       867           0           1           0           0             1
#> 46:       885           0           0           0           0             0
#> 47:       888           0           0           0           0             0
#> 48:       914           0           0           0           0             0
#> 49:       942           0           0           1           1             1
#> 50:       944           1           0           1           0             0
#> 51:       985           1           1           0           1             0
#> 52:       996           0           0           0           0             0
#> 53:      1028           0           0           0           0             0
#> 54:      1064           0           1           1           1             0
#> 55:      1153           0           0           0           0             0
#> 56:      1163           0           0           0           0             0
#> 57:      1169           0           0           0           0             0
#> 58:      1205           0           0           0           0             0
#> 59:      1231           0           0           0           0             0
#> 60:      1236           0           0           0           0             0
#> 61:      1238           0           0           0           0             0
#> 62:      1250           1           1           0           0             0
#> 63:      1255           0           0           0           0             0
#> 64:      1266           1           1           1           1             1
#> 65:      1292           1           0           1           1             1
#> 66:      1303           1           0           0           1             1
#> 67:      1313           1           1           1           0             1
#> 68:      1344           0           1           0           0             0
#> 69:      1409           0           1           1           0             1
#> 70:      1418           1           0           0           0             1
#> 71:      1435           0           1           0           0             1
#> 72:      1438           1           1           0           1             1
#> 73:      1441           0           0           0           0             0
#> 74:      1452           0           1           1           1             1
#> 75:      1455           0           0           0           0             0
#> 76:      1554           0           0           0           0             0
#> 77:      1566           0           0           0           0             0
#> 78:      1578           0           0           0           0             0
#> 79:      1586           0           0           0           0             0
#> 80:      1629           0           0           0           0             0
#> 81:      1664           0           0           0           0             0
#> 82:      1681           0           0           0           0             0
#> 83:      1699           0           1           0           0             0
#> 84:      1735           0           0           1           1             1
#> 85:      1738           0           0           0           0             0
#> 86:      1757           0           1           1           1             1
#> 87:      1763           0           0           0           0             0
#> 88:      1821           1           1           0           0             0
#> 89:      1864           0           0           1           0             1
#> 90:      1901           0           0           0           0             0
#> 91:      1924           0           0           0           0             0
#> 92:      1974           0           0           0           0             0
#> 93:      2013           1           1           1           1             0
#> 94:      2029           0           1           1           1             1
#>     person_id ethnicity_1 ethnicity_2 ethnicity_3 ethnicity_4 ethnicity_997
#>     ethnicity_999 race_1 race_2 race_3 race_4 race_5 race_997 race_999 hh_id
#>  1:             0      1      1      0      0      0        1        0   724
#>  2:             0      1      0      0      0      1        0        0    28
#>  3:             1      0      0      0      0      0        0        1   724
#>  4:             1      1      1      1      1      1        1        0   462
#>  5:             0      0      0      0      0      0        0        1   664
#>  6:             1      0      0      0      0      0        0        1   820
#>  7:             1      1      0      1      0      1        0        0   845
#>  8:             0      0      0      0      0      0        0        1   243
#>  9:             1      0      0      0      0      0        0        1   724
#> 10:             1      0      0      0      0      0        0        1   981
#> 11:             0      0      0      0      0      0        0        1   845
#> 12:             1      1      0      0      1      1        0        0   462
#> 13:             1      1      1      0      1      1        0        0   664
#> 14:             1      0      0      0      0      0        0        1   216
#> 15:             1      1      0      1      1      1        0        0   216
#> 16:             0      1      0      0      1      1        0        0    28
#> 17:             1      0      1      1      1      0        1        0   194
#> 18:             1      0      0      0      0      0        0        1   270
#> 19:             1      0      0      0      0      0        0        1   820
#> 20:             1      0      0      0      0      0        0        1   981
#> 21:             0      1      0      1      0      0        0        0   176
#> 22:             0      0      0      0      0      0        0        1   820
#> 23:             0      0      0      0      0      0        0        1   270
#> 24:             1      0      0      0      0      0        0        1    28
#> 25:             0      1      1      0      0      1        0        0   745
#> 26:             0      0      1      0      1      0        0        0   562
#> 27:             0      1      1      1      0      1        1        0   745
#> 28:             1      0      0      0      0      0        0        1    28
#> 29:             0      1      0      0      0      1        0        0   216
#> 30:             1      1      1      1      0      1        0        0   820
#> 31:             0      0      1      0      1      0        1        0   277
#> 32:             0      1      0      1      0      0        1        0   277
#> 33:             1      0      0      0      0      0        0        1   176
#> 34:             0      0      0      0      0      0        0        1   820
#> 35:             1      0      0      0      0      0        0        1   270
#> 36:             0      0      0      0      0      0        0        1   270
#> 37:             0      0      0      1      0      0        0        0   216
#> 38:             1      0      1      0      1      1        0        0   745
#> 39:             1      0      1      0      0      0        0        0   277
#> 40:             0      1      0      0      0      1        1        0   243
#> 41:             1      0      0      0      1      0        1        0   845
#> 42:             0      1      1      1      1      1        0        0   216
#> 43:             0      1      0      0      1      0        1        0   243
#> 44:             1      0      0      0      0      0        0        1   845
#> 45:             0      0      0      1      0      1        1        0   981
#> 46:             1      0      0      0      1      0        0        0   243
#> 47:             1      0      0      0      0      0        0        1   277
#> 48:             1      0      0      0      0      0        0        1   176
#> 49:             0      0      1      0      1      0        1        0   194
#> 50:             0      1      1      0      0      1        0        0   724
#> 51:             0      0      0      1      0      1        1        0   981
#> 52:             1      0      0      0      0      0        0        1   462
#> 53:             1      0      0      0      0      0        0        1   845
#> 54:             0      0      0      0      0      0        0        1   176
#> 55:             1      0      0      0      0      0        0        1   745
#> 56:             1      0      0      0      0      0        0        1   745
#> 57:             1      0      0      1      1      0        1        0   664
#> 58:             1      0      0      0      0      0        0        1   981
#> 59:             1      0      1      1      0      0        0        0   981
#> 60:             1      0      0      1      1      1        1        0   270
#> 61:             1      0      0      0      0      0        0        1   745
#> 62:             0      0      0      0      0      0        0        1   277
#> 63:             1      0      0      0      0      0        0        1   664
#> 64:             0      1      0      1      1      0        0        0   176
#> 65:             0      0      0      0      0      0        0        1   562
#> 66:             0      1      0      0      0      0        0        0   194
#> 67:             0      1      0      1      0      0        0        0   562
#> 68:             0      0      0      0      0      0        0        1   745
#> 69:             0      0      0      0      0      0        0        1    28
#> 70:             0      0      0      0      0      0        0        1   724
#> 71:             0      0      1      0      1      1        1        0   664
#> 72:             0      0      1      1      0      0        0        0   194
#> 73:             1      0      0      0      0      0        0        1   462
#> 74:             0      0      1      0      1      1        1        0   562
#> 75:             1      0      0      0      0      0        0        1   462
#> 76:             1      0      0      0      0      0        0        1   216
#> 77:             1      0      0      0      0      0        0        1   724
#> 78:             1      1      0      1      0      1        1        0    28
#> 79:             1      0      1      0      1      1        1        0   243
#> 80:             1      0      0      0      0      0        0        1   462
#> 81:             1      1      0      0      0      0        1        0   745
#> 82:             1      0      0      0      0      0        0        1   194
#> 83:             0      0      0      1      0      1        1        0   845
#> 84:             0      0      0      0      0      0        0        1   277
#> 85:             1      0      0      0      0      0        0        1   243
#> 86:             0      0      0      0      0      0        0        1   562
#> 87:             1      0      1      0      1      0        0        0   176
#> 88:             0      0      0      0      0      0        0        1   194
#> 89:             0      0      0      0      0      0        0        1   270
#> 90:             1      0      0      0      0      0        1        0   845
#> 91:             1      0      0      0      0      0        0        1   664
#> 92:             1      0      0      0      0      0        0        1   745
#> 93:             0      1      0      0      0      1        1        0   562
#> 94:             0      1      1      0      0      0        1        0   820
#>     ethnicity_999 race_1 race_2 race_3 race_4 race_5 race_997 race_999 hh_id
#>     age gender employment job_type education num_trips person_weight
#>  1:  11      2          3      995         2         0           128
#>  2:   5      2          1        5         7         8           492
#>  3:   7    995          1        5         6         0           871
#>  4:   3      2          5      995         4        11           683
#>  5:  10    995          2        1       995         4           736
#>  6:  11    999          1        1         6         0           608
#>  7:   6      2          1        1         1         8            59
#>  8:   1      1          5      995       995         0           572
#>  9:   1    999          1        2         4         8           394
#> 10:   9      4          6      995         6         2            15
#> 11:   3    999          1        1         3         6           850
#> 12:   9    999          1        1         4         5           890
#> 13:  10      2          1        1         2         8           163
#> 14:  11      4          5      995       999        10           791
#> 15:   1      2          1        5         7         5           553
#> 16:   1      2          2        2       999         0           895
#> 17:   5    995          5      995         6         9           978
#> 18:  10      2          5      995       999        10           688
#> 19:   5      1          5      995         7        20           427
#> 20:   2      2          5      995       999         1           682
#> 21:   9    999          1        3         3        10           179
#> 22:   6      4          5      995         6         3           951
#> 23:   3      2        995      995         2         8           446
#> 24:  11      2          3        3         3         8           989
#> 25:   1    999          5      995         6        10           884
#> 26:   5      1          5      995         4        11           194
#> 27:  11      4          3        3         5         5           730
#> 28:   8      2          6      995         7         3           375
#> 29:   1      4        995      995         7        14           128
#> 30:  10      2          1        1         2         7           646
#> 31:   4    999        995      995         1        15           804
#> 32:   4      1          2        1         4         0           648
#> 33:   6    999          1        1       999         5            31
#> 34:  11    995          5      995         5         0           825
#> 35:   3      1          1        5       999        20           337
#> 36:  11      4          1        3         2         4           954
#> 37:  12    999        995      995         2         0           479
#> 38:   6      2          5      995       995         4           386
#> 39:   1    995          6      995       995         4           831
#> 40:  12      4          1        1         2        11           544
#> 41:   6    995        995      995         1         3           577
#> 42:   7      2          1        5         6         9           856
#> 43:  11      1          1        5         2         6           556
#> 44:   3    995          3      995         1        16            52
#> 45:   3    995        995      995         6        10           690
#> 46:  12      1        995      995         3        17           227
#> 47:   9      2          1        5       995         4           649
#> 48:   3      4          1        5         3         3           426
#> 49:  11      4          1        1       995         5            33
#> 50:   9    995        995      995         1         8           389
#> 51:   9      1        995      995         2         0            21
#> 52:   2      2          1      995         1        19           618
#> 53:   3      2          1        1         7         9           223
#> 54:  11      4          1      995         1         4           967
#> 55:   1      1        995      995         1        13           166
#> 56:   1    999          1        5         5        24           788
#> 57:  11      2          5      995         4         4            92
#> 58:   1      4        995      995         5         6           540
#> 59:   7      2          1      995         2        26           586
#> 60:   1    999          1        5         4         0           336
#> 61:   5      1        995      995         7         8           321
#> 62:   5    999          3        2         5        15           566
#> 63:   2    999          1        5         4         9           537
#> 64:   6      1          1        1         6         9           376
#> 65:  12    995          2        1       999         7           432
#> 66:   1    999          5      995         1         3           860
#> 67:   1      2          1        2         4         0           113
#> 68:   3      4        995      995         7         3           962
#> 69:   7      1          5      995         5         5           586
#> 70:  11      4          1        5         7         9           594
#> 71:  12      4          1        2       995         5           604
#> 72:   4    999          2        3         7         0           884
#> 73:  11      2          1        5         7         0           590
#> 74:  11      4          3        3       995         8           171
#> 75:  10      2          1        1       995        12           678
#> 76:   4      4          1      995         4         5            51
#> 77:   3    999          1        1         4         6           620
#> 78:  12      2          1        5         1        13           339
#> 79:   3      1          1        1         2         0           474
#> 80:  12    999          2      995         2         0           222
#> 81:   9      4          5      995         6         5           396
#> 82:  12    999          5      995         2         3           287
#> 83:   1      1          5      995         2        18           100
#> 84:   5      2          1        5         1        18            89
#> 85:   9      2          1        2       999         1           578
#> 86:   1    995          5      995       999         0           872
#> 87:  10    995          1        5       999         4           937
#> 88:  12      4          3        5       999         8           321
#> 89:   9      4          5      995         4         6           409
#> 90:   3    995          6      995         6         6            51
#> 91:   7      1          1        1         4        13           294
#> 92:  12    995          1        1         4        14            94
#> 93:   8      2        995      995         3        18           659
#> 94:   2      4          1        3         4        10           438
#>     age gender employment job_type education num_trips person_weight
#> 
#> $day
#>      day_id person_id delivery_2 delivery_3 delivery_4 delivery_5 delivery_6
#>   1:     39       153          0          0          0          1          0
#>   2:     66       578          0          0          0          0          0
#>   3:     99       885          0          0          0          0          0
#>   4:    108       519          0          0          0          0          0
#>   5:    117        56        995        995        995        995        995
#>  ---                                                                        
#> 179:   4085       153          0          0          0          0          0
#> 180:   4098      1231          0          0          0          0          0
#> 181:   4099       525          0          0          0          1          0
#> 182:   4116      1664        995        995        995        995        995
#> 183:   4117      2013        995        995        995        995        995
#>      delivery_7 delivery_8 delivery_996 travel_date begin_day end_day hh_id
#>   1:          0          0            0  2023-05-16         1       1   845
#>   2:          0          0            1  2023-04-29         1       1   176
#>   3:          0          0            1  2023-04-26         1       1   243
#>   4:          0          0            1  2023-06-07         1       1   216
#>   5:        995        995          995  2023-05-28         1       1   462
#>  ---                                                                       
#> 179:          0          0            1  2023-05-15         1       1   845
#> 180:          0          0            1  2023-06-08         1       1   981
#> 181:          0          0            0  2023-05-08         1       1   820
#> 182:        995        995          995  2023-04-21         1       1   745
#> 183:        995        995          995  2023-04-20         1     995   562
#>      num_trips day_weight
#>   1:         4        519
#>   2:         3        199
#>   3:         3        614
#>   4:         2        381
#>   5:         6         66
#>  ---                     
#> 179:         2        449
#> 180:         2        454
#> 181:         4        272
#> 182:         1        390
#> 183:         7         44
#> 
#> $trip
#>      day_id trip_id speed_mph distance_miles mode_type mode_1 mode_2
#>   1:     39    7123  9.505124      1.5841873         8      6    995
#>   2:     39    2763 26.539083      4.7328031         8     34    995
#>   3:     39    9715 16.791985      6.9966606         8      6    995
#>   4:     39    5116 14.918498      1.7404915         8      6    995
#>   5:     66   11311 42.142684      9.1309148         8     49     22
#>  ---                                                                
#> 680:   4117   13390 79.054610      0.1537173         1      1    995
#> 681:   4117    5446  2.317582      0.4557911         1      1    995
#> 682:   4117    5688 31.027928      3.4044533         8      7    995
#> 683:   4117    9478 31.305647     46.9584709         8      7    995
#> 684:   4117   14114  8.680979      1.4468299         8      6    995
#>      num_travelers d_purpose_category hh_id person_id travel_date trip_weight
#>   1:             1                  7   845       153  2023-05-16         903
#>   2:             2                 12   845       153  2023-05-16         308
#>   3:             4                  7   845       153  2023-05-16         903
#>   4:             1                  7   845       153  2023-05-16         383
#>   5:             5                  8   176       578  2023-04-29         459
#>  ---                                                                         
#> 680:             4                  8   562      2013  2023-04-20         888
#> 681:             2                  7   562      2013  2023-04-20         613
#> 682:             2                  1   562      2013  2023-04-20         909
#> 683:             1                  2   562      2013  2023-04-20         937
#> 684:             3                  9   562      2013  2023-04-20         443
#> 
#> $vehicle
#>     hh_id vehicle_id fuel_type hh_weight
#>  1:    28        427         1       522
#>  2:   194        101         1       591
#>  3:   216       1321         1       972
#>  4:   270        378         5       355
#>  5:   270        418         1       355
#>  6:   462       1422         1        15
#>  7:   664       1334         1       524
#>  8:   664         85         5       524
#>  9:   724        321         2       664
#> 10:   745         46         1       678
#> 11:   845       1425         1       498
#> 12:   981        142         1       414
#> 13:   981        446         1       414
#> 14:   981        644         1       414
#>