knitr::opts_chunk$set(echo = TRUE)
This package provides functions to read data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System. The package also provides functions that summarize the data for you.
FARS is a US nationwide census providing the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes.
This package is used as a development version on GitHub and was built for passing a course on Coursera. To use the package, you can install it directly from GitHub using install_github
from devtools
.
The following code will install the package fars
:
library(devtools) install_github("VeerlevanLeemput/fars") library(fars)
There are three datasets included in the package. This data includes information on accidents of 2013, 2014 and 2015. Sample data is available and can be obtained by the following code:
filepath1<-system.file("extdata", "accident_2013.csv.bz2", package = "fars") filepath2<-system.file("extdata", "accident_2014.csv.bz2", package = "fars") filepath3<-system.file("extdata", "accident_2015.csv.bz2", package = "fars")
The package provides several functions to help read, summarise and visualise the data. These are fars_read
, make_filename
, fars_read_years
, fars_summarize_years
and fars_map_state
.
Use of the above mentioned functions are shown below.
This function reads the fars data files and transforms to a workable R dataframe table.
fars_read("filename.csv")
This function provides a filename, when a certain year is given. This way filenames will be consistent.
make_filename(2017)
The function fars_read_years
generates a dataframe with months and years for a provided series of years. This way, you will be able to quickly overview what months and years are avaible.
fars_read_years(c(2013, 2014, 2015))
The fars_summarize_years
function summarises the total number of accidents by month and year.
Enter years as a vector or integer years in YYYY format (eg 2013).
fars_summarize_years(c(2013, 2014, 2015))
The fars_map_state
function generates of map of the location of accidents within the specified US state during the specified year.
Enter the State number (eg 1) and the year to be analysed in YYYY format eg 2011.
fars_map_state(1, 2014)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.