read_data: Read HTS data and weights.

Description Usage Arguments Details Value Examples

View source: R/read_data.R

Description

Read HTS data and weights.

Usage

1
read_data(dataset, csv_path = getwd(), select = select_all(dataset))

Arguments

dataset

The study year of the dataset. Currently supports "2001" and "2009".

csv_path

The parent directory of "/csv/dataset/". Defaults to working directory.

select

A character vector of NHTS variable names to select for analysis. Defaults to all variables in the codebook.

Details

read_data is a wrapper for reading in variables from the correct csvs and merging the corresponding tables on correct keys. fread and merge are used for performance benefits.

Value

read_data returns an object of class "HTS.data". It contains the data files and weights necessary for querying the NHTS dataset, used primarily by summarize_data.

The "HTS.data" object is essentially a list of data.tables broken up by data and weights.

Accessing the data:

Accessing the weights:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Read 2009 NHTS data with specified csv path:
nhts_data <- read_data('2009', csv_path = 'C:/NHTS')

# Access the data
nhts_data$data$household     # household data
nhts_data$data$person        # person data
nhts_data$data$trip          # trip data
nhts_data$data$vehicle       # vehicle data

# Access the weights
nhts_data$weights$household  # household weights
nhts_data$weights$person     # person and trip weights

Westat-Transportation/summarizeNHTS documentation built on May 17, 2020, 8:57 p.m.