knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(FARSdatatools)
The object of this package is to provide users with tools to analyze data compiled by the National Highway Traffic Safety Administration (NHTSA) via the Fatality Analysis Reporting System (FARS). All publicly available FARS data is accessible here.
The specific data set for which this package is designed is available for download here. THE USER MUST PLACE THESE DATA FILES IN THE CURRENT WORKING DIRECTORY IN ORDER FOR THE FUNCTIONS IN THIS PACKAGE TO ACCESS THEM.
NOTE: The specific data set linked above only contains data for the years 2013, 2014, and 2015.
The primary tools provided by this package are the functions
fars_summarize_years fars_map_state
Additionally, the helper functions
fars_read make_filename fars_read_years
are made available to the user.
All functions (including the helper functions) are documented fully in the man files.
This documentation can be easily accessed from the console using the ?
operator, e.g. ?fars_read
. This vinnette focuses on elaborating on the use of
fars_summarize_years
and fars_map_state
.
The fars_summarize_years
function takes a single input parameter years
.
This value may be a single year or a vector/list of years so long as all values
are integers, numeric, or character strings which are coercible to one of the integers
2013, 2014, or 2015. It then summarizes for each value in years
the monthly accident totals for that year. It does this by extracting data from a file of accident records for user-specified years and using various methods from the dplyr
and tidyr
packages (members of tidyverse
) to return a summary data table as a tibble. For example, the result of calling
fars_summarize_years(c(2013,2015))
is a 12x3 tibble with column names c("MONTH","2013","2015")
where the
"MONTH"
column contains the integers from 1 to 12 enumerating the month
and the "2013"
and "2015"
columns contain the corresponding monthly
accident totals for those years.
The fars_map_state
function takes two two input parameters, state.num
and year
. The year
is the year for which data is desired and the
state.num
parameter is a unique identifying number (FIPS code) for a state. The function uses these parameters to retrieve accident location (longitude and latitued) data for the specified year and state and plots a scatter plot of the
coordinates superimposed on a simple state map allowing the user to quickly acertain the spacial distribution of traffic accidents for the given year and state.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.