knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(farsdata)
This package was built as the second assignment for the "Buildung R Packages" course on Coursera. It allows to work with fatal traffic accident data from 2013-2015. The data, which comes with this package, comes from the National Highway Traffic Safety Administration (NHTSA) Fatality Analysis Reporting System (FARS). For further information see: https://www.nhtsa.gov/Data/Fatality-Analysis-Reporting-System-(FARS)
To load the data for a specific year into the R-environment, use the functions make_filename()
and fars_read()
. This is illustrated in the following example:
# creating a filename filename<-make_filename(2013) # loading the corresponding data fars_read(filename)
The data is stored in the inst/extdata sub-dirctory of this package. One can see the complete path by running the make_filename()
function.
If you want to see the accidents for a particular year or multiple years, use the function fars_read_years()
The folowing example illustrates the functionality of this function:
# creating tibble/data.frame for single year fars_read_years(2013) # creating tibble/data.frame for multiple years fars_read_years(c(2013,2014))
If one wishes to get a summary of the accidents in given years, use the function fars_summarize_years()
.
Note that the input for fars_summarize_years()
and fars_read_years()
are the same.
The folowing example illustrates the functionality of this function:
# creating a summary for multiple years fars_summarize_years(c(2013,2014))
The package comes with a visualization function, which takes a state-ID and a year as input arguments, and creats a plot/map where the accidents are marked with a dot.
# map of accidents for state-ID: 1 and year: 2013 fars_map_state(1,2013)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.