Overview of the package functions

The functions included in this packages are:

|Function |Description | |:------------------------|:------------------------------------------------| |fars_read() |Read csv files | |make_filename() |Make a file name | |fars_read_years() |Load MONTH and year into R | |fars_summarize_years() |Count the number of accidents per month and year | |fars_map_state() |Plot the location of accidents on US maps |

Data Source

The functions contained in this package are created for manipulating 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.

Data can be found here

Reading csv files

This function loads a csv file in R and converts it to a data frame tbl Here is an example on how to use this function:

dt <- fars_read("accident_2013.csv.bz2")

Make a file name

This function combines text with an input value to create a file name for the data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System.

#Include a list of years
make_filename(list(2013, 2014, 2015))
#Include only a subset of numerical value
make_filename(2014:2015)

Load MONTH and year

This function reads yearly and monthly data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System and returns an error if the selected years are not written corrected, found in the working directory files or if the working directory is not set properly.

l <- fars_read_years(2013)

Count the number of accidents per month and year

This function load data from data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System, binds the yearly data together, group by year and month, counts th number of accidents and spread the results with month in rows and a year per column.

head(fars_summarize_years(2013:2015))

Plot the location of accidents on US maps

This function load accident data from the US National Highway Traffic Safety Administration's Fatality Analysis Reporting System, into R for a specified year and state numbers, validate the parameters and plot the location of accidents on a US map.

fars_map_state(c(1:56),2014)

References

Peer Assignment in Coursera Course "Building R Packages".



ivalette/faRs documentation built on May 18, 2019, 7:12 a.m.