library(farsdata)
This is a simple package which provides functions helping you to explore the data given by the National Highway Traffic Safety Administration (NHTSA), called Fatality Analysis Reporting System (FARS). The background of the package is the final assignment of the Coursera course "Building R Packages".
Given are data of three years:
- accident_2013.csv.bz2
- accident_2014.csv.bz2
- accident_2015.csv.bz2
Each file containing the data of fatal vehicle crashes within the United States.
An example of the head of the 2013 data file is shown below:
# require(farsdata) # name_2013 <- make_filename(2013) # fars_2013 <- fars_read(name_2013) # dim(fars_2013) # head(fars_2013)
To load the data, you can work with the given functions within this package:
- make_filename()
- fars_read()
- fars_summarize_years()
- fars_map_state()
Depending on which year you would like to load, the filename can be accordingly created:
# name_2013 <- make_filename(2013) # name_2013
Data of one single year can be loaded via the fars_read_years()
function and have only one year as the input. Make sure, that you have the working directory correctly
# fars_2013 <- fars_read_years(2013) # fars_2013[[1]]
Same approach, but with various year as input
# fars_3years <- fars_read_years(2013:2015)
the fars_summarize_years()
function takes the loaded data and applies a summarize function on it: in this case, it counts the fatalities by month and year:
# fars_summary <- fars_summarize_years(2013:2015) # fars_summary
Finally, the fars_map_state()
function takes the state ID and a year as an input and plots the fatality. Make sure you have the mapdata
package loaded.
# require(mapdata) # fars_map_state(53, 2014) # fars_map_state(36, 2014)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.