knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
This imports and generates summary on fatal accidents based on data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System. Data source: Fatality Analysis Reporting System (FARS)
library(Far)
The package includes some datasets as follows
list.files(system.file("extdata", package = "Far"))
make_filename
The make_filename(year)
function accepts a numerical value such as 2013, 2014, 2015. It'll then output the concatenated file name as 'accident_year.csv.bz2', etc.
make_filename(2013)
fars_read
Accepts a csv file and output it as a dataframe
df_fars <- fars_read("accident_2015.csv.bz2") head(df_fars, 3)
fars_read_years
This function returns MONTH column of each year as a combined list. Input should be 2013, 2014, 2015, otherwise the function will generate an error message
This function uses make_file_name
and fars_read
as ancillary functions.
fars_read_years(2013:2015)
fars_summarize_years
This function returns the number of total fatal accident per month in 2013, 2014, 2015 respectively. It uses fars_read as ancillary functions.
fars_map_state
fars_map_state(state.num = 30, year = 2013)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.