knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Description

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)

Load Packages

library(Far)

Load Data

The package includes some datasets as follows

list.files(system.file("extdata", package = "Far"))

Package Functions

Function 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)

Function fars_read

Accepts a csv file and output it as a dataframe

df_fars <- fars_read("accident_2015.csv.bz2")
head(df_fars, 3)

Function 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)

Function 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.

Function fars_map_state

fars_map_state(state.num = 30, year = 2013)


AyeshaPerera/Far documentation built on July 29, 2020, 7:34 a.m.