FARS
R package reads, summarizes and plots Fatality Analysis Reporting System (FARS) data from the National Highway Traffic Safety
Administration.
The packages consists of five functions:
make_filename
fars_read
fars_read_years
fars_summarize_year
fars_map_state
The functions provided for you in this assignment will be using data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System, which is a nationwide census providing the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes. Once the package is installed 3 example files are accessible as follows:
system.file('extdata', 'accident_2013.csv.bz2', package = 'FARS') system.file('extdata', 'accident_2014.csv.bz2', package = 'FARS') system.file('extdata', 'accident_2015.csv.bz2', package = 'FARS')
library(FARS) library(maps)
make_filename
This function reads a year number as an integer and adds it to the general filename "accident_.csv.bz2", to create a string filename "accident_YEAR.csv.bz2".
make_filename(2015) make_filename("2013")
fars_read
This function reads a csv file (can be compressed in bz2 format) & returns a data frame (tibble) with the loaded data.
fars_read("accident_2015.csv.bz2")
fars_read_years
This function reads the data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System, which is a nationwide census providing the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes from a file type "accident_YEAR.csv.bz2", creates a data frame with multiple columns and selects the specified Years and their correspondent Month columns. Then it creates a list with separate data frames for each year. Each data frame contains two columns: month and year.
fars_read_years(2013:2015) fars_read_years(2014)
fars_summarize_years
This function reads the data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System, which is a nationwide census providing the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes.Then creates several data frames in a list, groups them by year, makes a summary of the number of accidents by MONTH and creates a data frame with this data with Year's as columns and MONTH's as rows.
fars_summarize_years(2013:2015) fars_summarize_years(2014)
fars_map_state
This function reads the data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System, which is a nationwide census providing the American public yearly data regarding fatal injuries suffered in motor vehicle traffic crashes. Then selects data from a specific state and a specific year and plots the location of the accidents in a map of the state.
fars_map_state(1,2015)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.