This package contains routings designed for processing and visualizing of the data files provided by US National Highway Traffic Safety Administration's Fatality Analysis Reporting System, which is a US nationwide census providing the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes. The raw data files for years 2013, 2014 and 2015 are included in the package and can be accessed by the following code:
year <- as.integer(2014) system.file("extdata", sprintf("accident_%d.csv.bz2", year), package = "Fars")
Fars package consist of a few function, providing access to this data, some simple processing and visualising. This functions are descibed below.
knitr::opts_chunk$set(echo = TRUE, warning=FALSE) library(Fars)
Read accidents statistics by the given file name Open file with accidents statistics by the given file name and read it into dplyr::tbl_df variable.
Parameters
filename - character string with file name
output
dplyr::tbl_df data frame with accident`s data
examples
name <- system.file("extdata", sprintf("accident_%d.csv.bz2", 2014), package = "Fars") data <- fars_read(name) data[1:3, 1:10]
Function returns full filename of the accident data stored as a raw files in a package as character by the given year
Parameters
year - year of accidents
output
filename - full file name as a character string
examples
make_filename(2014)
Read accident`s data by given years and return data frame with short info for each accident.
Parameters
years - vector of years
output
Data frame of class dplyr::tbl_df with two columns (month ans year) per each accident. If data for any of given years do not exist function stops working and return an error message.
examples
data <- fars_read_years(c(2013, 2014, 2015)) data[[1]]
Function takes given vector of years and summarize statistical data about accidents.
Parameters
years - vector of years
output
Data frame with summary about accidents in the given years: quantity of accidents per month for each year. If data for any of given years do not exist function stops working and return an error message.
examples
fars_summarize_years(c(2013, 2014, 2015))
Function fars_map_state() draw a map of state with accidents on it by the given state and year. Accidents are represented as points.
Parameters
year - interested year of accidents
state.num - USA state code
output
Graphical map.
examples
fars_map_state(state.num = 1, year = 2014)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.