library(FarsDataAnalysisPD)
library(magrittr)

This vignette provides a brief introduction to using the FarsDataAnalysisPD package. This package provides tools to read and analyze the National Highway Traffic Safety Administration's (NHTSA) Fatality Analysis Reporting System (FARS) data. This package contains the following functions:

Raw Data

This package includes FARS data from three years: 2013, 2014, 2015. A snapshot of the 2013 data is as follows:

readr::read_csv(system.file("extdata", "accident_2013.csv.bz2", package = "FarsDataAnalysisPD")) %>% 
  head(10)

In the next sections, we will see how to read in and process this data.

Read in FARS data

FARS data can either be read in for a single year or multiple years. To read in a single year of data, first utilize the make_filename function to create a filename for the given year of interest. Then, use fars_read to read in the file.

FARS_data_2013_file <- make_filename(2013)
FARS_data_2013 <- fars_read(FARS_data_2013_file)

To read multiple years of data, use the fars_read_years function:

FARS_data_multiple <- fars_read_years(2013:2015)

This creates a list containing the individual data files. Of course, this function could be used to read a single year of data as well.

Summarizing FARS data

To summarize the number of accidents by month for a set of years, use the fars_summarize_years function. For example, to summarize the accidents for years 2013 - 2014, run

fars_summarize_years(2013:2014)

Plot Accident Fatalities by State

The fars_map_state function takes a state ID number and year, and produces a map of accident fatalities for the given state.

fars_map_state(1, 2013)


Paul-Draper/FarsDataAnalysisPD documentation built on May 23, 2019, 5:02 a.m.