The rfars package bundles a set of functions to analyze the data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System (FARS).
The function fars_read()
allows you to extract the data (samples in the "data-raw" folder) from a compressed format, and store it in a special R object.
# Extracts the data from a compressed file. library(rfars) data_2013 <- fars_read("accident_2013.csv.bz2") head(data_2013)
The fars_read_years()
function does the same, but without having to name the entire file. Just provide the year(s) of the data of interest!
Note: the function make_filename()
also exists, but is mostly just an intermediate function.
In order to get the total number of fatalities by month, you can use the fars_summarize_years()
function, without even having to read in the raw data first (it does it for you)!
# Creates a table by month & year with the total number of fatalities in 2013 y 2014. fars_summarize_years(c(2013, 2014))
The function fars_map_state()
creates a map with the car fatalities in a US state (or states, by number code) from a specific year (again, pre-reading in the data is not necessary, as the function does it for you!).
# Plots the car fatalities for the state of Florida (12) in 2015. fars_map_state(12, 2015)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.